Database Reference
In-Depth Information
Class
Definition
Class
Instances
STORE
Class Attributes
StoreNo: 317
StoreLocation: Main St.
City: Milltown
……………
StoreDailyTotal
Instance Attributes
StoreNo
StoreLocation
City
……………
StoreNo: 521
StoreLocation: Oxford
City: Boston
……………
StoreNo: 333
StoreLocation: Ginza
City: Tokyo
……………
Figure 20-3
Class definition and class instances.
A Class A class is used as a template to create objects of the same structure.
Objects having the same attributes and performing the same operations can be put
together as a class.
Consider a class STORE. Attributes and actions may be defined once for
the class. Then all store objects can be described by the attributes and actions
defined for the class STORE. Each such store object is an instance of the STORE
class.
A class itself may also be considered as an object and have its own special attrib-
utes and operations. These are class attributes describing the general characteristics
of the entire class. For example, StoreDailyTotal may represent the total sale
amount for all the stores.
Figure 20-3 illustrates a class definition and class instances.
Methods and Messages
In our discussion on encapsulation, you have noted that an object contains both the
data structure and operations or functions as a self-contained, independent package.
Methods The functions or operations encapsulated by an object are known as
methods. Methods indicate the behavior of the object. We mentioned that the
current state of an object is defined by the current values of its attributes. Methods
can be utilized to change the values of the attributes and thereby change the state
of an object. A method in the CUSTOMER class may be defined to effect an
address change to a customer instance. Another method may be stipulated to print
the customer name and address.
Figure 20-4 shows the representation of the CUSTOMER class, object instances,
and an example of a method defined within the class.
Search WWH ::




Custom Search