We now have now added object-oriented terminology in our arsenal of definitions. We defined objects as instances of classes, where it is an object of its own set of data and behaviors.
1.Data describes objects
Data represents roughly the individual characteristics of an object. The class of an object defines a specific characteristics that are shared by all instances of the defined class.
On the other hand, each instances would have different data values for each shared characteristics. For example, the length of the tail of a dog of the following classes are of different values:
Fruit Inventory Application
We may want to know what orchard the orange came from, when it was picked, and how much it weights. We may also want to keep track of where each basket is stored. We might also have color attribute for our fruits (e.g. apple), and barrels might come in different sizes.
Depending on how detailed our design needs to be, we can also specify the type for each attribute.
This is one area where the design stage can overlap with the programming stage. Most of the times we don't have to worry with this at the design stage, as implementation-specific details are chosen during the programming stage.
2.Behaviors are actions
Behaviors are actions that occur on an object. A behavior that can be applied to a specific class of objects is called a method. In programming, method are like functions, but it has access to all the data associated with that objects.
Like functions, methods can accept parameters and return values.
Numbers is a simple example of an object. With methods that includes the arithmetic operations addition and multiplication.
An action that can be associated with oranges in our application is the pick action. Pick would place the orange in a basket by updating the basket attribute on the orange, and by adding the orange to the oranges list on the Basket.
Basket can have a sell action. When a basket is sold, our inventory system might update some data on as-yet unspecified objects for accounting and profit calculations.
We can also add a discard method in case our basket of oranges might go bad.
Adding models and methods to individual objects allows us to create a system of interacting objects.
Object-oriented analysis and design is all about figuring out what those objects are and how they should interact.