The Essence of Objects
Object
orientation is the culmination of years of experience in finding an effective
way to develop software, and is certainly the dominant method used to develop
major software systems today. Object orientation is a technique of modeling a real-world
system in software based on objects. The object is the core concept.
The
attributes, or data, used inside an object are really only a tiny part of what
an object is and does. An object also has a set of responsibilities that it
carries out by providing services to other objects. It is often more useful to
think of an object in terms of its responsibilities rather than its attributes.
For example, it is the responsibility of a sensor object to keep track of the
state of the sensor. A sensor object might respond to requests from other
objects that use sensors to check the status of a sensor, to turn a sensor on
or off, or to report on the sensor's values.
While
a program is running, individual objects usually don't stand alone. They belong
to a collection of other similar objects that all are members of the same
group, or class. A program will be made up of many different classes, each
class made up of similar objects.
·
class A class is a description of a set of
objects. The set of objects share common attributes and common behavior. Class
is similar in concept to abstract data types found in non- OO programming
languages, but is more comprehensive in that it includes both structure and
behavior. A class definition describes all the attributes of member objects of
that class, as well as the class methods that implement the behavior of member
objects.
·
object The basic unit of object orientation. An
object is an entity that has attributes, behavior, and identity. Objects are members
of a class, and the attributes and behavior of an object are defined by the
class definition.
What Is an Object-Oriented
System?
Any object-oriented software
system will have the following properties:
- ·Abstraction with objects
- Encapsulated classes
- Communication via messages
- Object lifetime
- Class hierarchies
- Polymorphism
·
· object orientation A method of
developing software that uses abstraction with objects, encapsulated classes, communication
via messages, object lifetime, class hierarchies, and polymorphism.
Fundamental
Properties of an Object-Oriented System
Abstraction with objects
An
abstraction is a mechanism that allows a complex, real world situation to be
represented using a simplified model.abstraction A model of a
real-world object or concept.
Encapsulated classes
encapsulation
The
process of hiding all the internal details of an object from the outside world.
In Java, encapsulation is enforced by having the definitions for attributes and
methods inside a class definition.
Interaction
via messages
In
order to accomplish useful tasks, objects need to interact with other objects.
The interaction can be between objects of the same class, or objects of
different classes. This interaction is handled by sending messages (in Java,
this is done by calling methods) to other objects to pass information or
request action.
Object
lifetime
All
objects have a lifetime. Many objects that are instances of the same class can
exist at any given time. Each object has a unique identity, and will have
attributes that are different from other instances of objects in the same
class.
Class
hierarchies
An
ordering of classes. The most common OO hierarchies are inheritance and
aggregation.In an OO design, classes of objects are arranged into hierarchies
that model and describe relationships among the classes. Hierarchies can also
be used to build the definitions of individual classes. This kind of hierarchy
is called inheritance.
Polymorphism
Polymorphism
is the final fundamental characteristic of objectoriented systems. When
inheritance is used to extend a generalized class to a more specialized class,
it will usually include extending some of the behaviors of the generalized
class.
Abstraction with Objects
Abstraction
is one of the basic tools of all programming, not just OO
programming. When trying to
write a program to solve some real world problem, abstraction serves as a way
model the real world problem. It can be a real-world thing or concept, or an abstraction
of a thing or concept, expressed as
a software
representation.
Encapsulated Classes
Encapsulation
is one of the most important aspects of OO. It is what allows each object to be
independent.
The
class definition is the main programming tool that is used to implement
encapsulation. A class is a description of a collection of with common
attributes, behavior, and responsibilities.
·
attribute Used to hold state information of an
object. An attribute might be as simple as an on or off boolean variable, or it
might be a complex structure such as another object. A class definition
describes the attributes and operations (methods) of a class.
·
behavior The activity of an object that is
visible to the outside world. Includes how an object responds to messages by changing
its internal state or returning state information to other objects.
·
method An operation or service performed upon
an object, defined as part of the declaration of a class. Methods are used to
implement object behavior. Synonyms for method include member function,
operation, and service.
·
state State reflects the current values of all
the attributes of a given object, and is the result of the behavior of an
object over time.