| |
Designing a Class | page 3 of 11 |
One of the advantages of object-oriented design is it allows a programmer to create a new abstract data type that is reusable in other situations
When designing a new data type, two components must be identified - attributes and behaviors.
Consider the icons used in computer operating systems. The attributes that describe the icon are things like a graphic pattern, colors, size, name, and its position on the screen. Some of its behaviors include changing color and moving its position.
The attributes of an object are the nouns that describe that object. For example, in our checking account example below, the attributes are "current balance" and "account number". These will become the private data members of a class.
The behaviors of an object are the verbs that denote the actions of that object or what it does. For example, in our checking account example below, behaviors are "accept a deposit", "process a check", etc. These will become the member functions of a class. In a Java program, behaviors of an object are described by methods.
|