Booch [BRJ99] defines a class as description of a set of objects that share the same attributes, operations, relationships, and semantics. Classes are the most important building block of any object-oriented system. In a specific domain, there are many objects that can share commonalities. It is important to abstract features that are common to objects. Then, these common features will be used to construct a class. Abstraction is used to depict commonalities between objects and construct classes. A class is not an individual object, but rather a pattern to create objects with same properties and behavior. Objects created by a class are instances of this class.

Some authors refer to a class as an "object factory," a factory that knows how to produce objects. Other metaphors are "rubber stamps" or "blueprints."

A class has a unique name and all classes defined in a domain have different names.

In Figure 3-1 there are three objects: A pear, a strawberry, and grapes. These objects have different colors, shapes, and taste but they have in common the fact that they are fruits. They all can be represented by class Fruits and each of them is an instance of the class Fruits. The class Fruits should be designed to represent common characteristics of each of the instances.

An attribute is a named property of a class that describes a range of values that instances of the property may hold [BRJ99]. Attributes hold information about the class and they define the state of the object created by the class. Each attribute can hold values independently of one another. A class may have any number of attributes or no attribute at all.

An attribute has a name, and it is advisable to name attributes with meaningful names that represent this particular abstraction expressed in the attribute. An attribute has a type that defines the kind of values that can be stored in it. An attribute is an abstraction of the kind of the data an object of the class may have as value.

Class Fruits has an attribute named fruitName used to hold the name of the fruit. All instances of this class will have this attribute, but the value of the attribute may be different. If an instance of the class Fruit is created and the attribute fruitName is set to "Apple," then it shows that the instance created is an apple.

Figure 3-1. Examples of objects.
0 0

Post a comment