An object is an instance of a Class. The relationship is such that many objects can be created using one class. Each object has its own data but its underlying structure (i.e., the type of data it stores, its behaviors) are defined by the class
Objects are key to understanding object-oriented technology. Look around right now and you'll find many examples of real-world objects: your dog, your desk, your television set, your bicycle.
Real-world objects share two characteristics: They all have state and behavior. Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles also have state (current gear, current pedal cadence, current speed) and behavior (changing gear, changing pedal cadence, applying brakes). Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming.
Hey, Just take a minute right now to observe the real-world objects around you. For each object that you see, ask yourself two questions: "What possible states can this object be in?" and "What possible behavior can this object perform?".
Now write down your observations. As you do, you'll notice that real-world objects vary in complexity;
your desktop lamp may have only two possible states (on and off) and two possible behaviors (turn on, turn off), but your desktop radio might have additional states (on, off, current volume, current station) and behavior (turn on, turn off, increase volume, decrease volume, seek, scan, and tune).
You may also notice that some objects, in turn, will also contain other objects. These real-world observations all translate into the world of object-oriented programming
No comments:
Post a Comment