Wednesday, December 17, 2014

Structural and behavioral concepts in OO

Structural and behavioral concepts in OO

 

Okay, time to get a little more formal about OO. In this section, I define and
explain the core OO terminology while bringing in additional concepts that
complete the building blocks of OO.
Object
An object is an individual, identifiable item, either real or abstract, that contains
data about itself and descriptions of its manipulations of the data. In other
words, an object might be either
? Something real and tangible, like the items in a kitchen
? A pure concept, such as a mathematical concept, like an integral
Identifying objects is the first step in analyzing a domain (as shown in the
previous section by identifying Vessel, Teacup, Bowl, Stove, and so on).
Each object is considered an instance of a class.
Class
A class is a description of the organization and actions shared by one or more
similar objects.
A type is a concept similar to that of class, and they’re often used interchangeably.
Within programming languages, a class also has a technical meaning.
It is a template of an object, through which new objects can be created.
However, the concept of a type separate from that of a class is captured in
many programming languages (but not Objective-C) by a programming construct
called an interface. Objective-C doesn’t make a distinction between type and
class, so this book doesn’t use the term type.
In the earlier DrinkableFoodRecipe example, Vessel is a class. All the
objects Faucet, ServingVessel, and Stove in DrinkableFoodRecipe
are instances of classes.
Object-orientation also has the concept of a metaclass, whose instances
are classes. There is one metaclass in Objective-C called Class. You see
this metaclass used in the EatingVesselType member variable in the
DrinkableFoodRecipe class.
Abstraction
When I identified the classes of objects and their capabilities in my example,
I didn’t consider those classes or capabilities that weren’t relevant to the
domain of cooking. For example, it’s unlikely I would have brought in a class
to represent the floor or the lighting in the kitchen. Nor would I bring in the
capability of a teacup to be thrown.
This kind of modeling where I ignore what is irrelevant to focus on what is
relevant for a particular domain is known as abstraction. Abstraction is the
act of identifying the classes (and types) needed in order to pare down to
those aspects that are relevant to the problem.
Generalization
The concept of generalization is exemplified in the relationship between
the classes Vessel and Teacup. Generalization in a programming language
is demonstrated through a mechanism known as inheritance, which allows
the data and behavior of one class to be included in or used as the basis for
another class.
Several programming languages have a root class from which all classes
are inherited. In the Objective-C framework, the class is called NSObject.
NSObject is equivalent to the class Object in Java.

No comments:

Post a Comment