What
is object orientation?
The term object orientation (OO) means
that we organize software as a collection of discrete objects that incorporate
both data structure and behavior.
There is some dispute about exactly what
characteristics are required by an OO approach, but they generally include four
aspects:
1.
identity,
2.
classification,
3.
inheritance,
4.
Polymorphism.
Identity means that data
is quantized into discrete, distinguishable entities called objects. Workstation
and the white queen in a chess game are examples of objects.
Classification means that
objects with the same data structure (attributes)
and behavior (operations) are
grouped into a class. Paragraph, Monitor, and Chess Piece are examples of
classes.
A Class is an abstraction that
describes properties important to an application and ignores the rest. Any
choice of classes is arbitrary and depends on the application.
Each class describes a possibly infinite
set of individual objects. Each object is said to be an instance of its class. An object has its own value of each
attribute but shares the attribute names and operations with other instances of
the class.
Inheritance is a kind of attributes and operations (features) among classes based on a
hierarchical relationship. A super class
has general information that
subclasses refine and elaborate.
Each subclass incorporates, or inherits; all the features of its super class
and adds its own unique features. Subclasses need not repeat the features of
the super class. For example, scrolling Window and fixed window are subclasses
of window. Both subclasses inherit the features of window, such as visible
region on the screen. Scrolling Window adds a scroll bar and an offset. The
ability to factor out common features of several classes into a super class can
greatly reduce repetition within design and programs and is one of the main
advantages of OO technology.
(or)
Inheritance
allows the extension and reuse of existing code, without having to repeat or
rewrite the code from scratch. Inheritance involves the creation of new
classes, also called derived classes, from existing classes (base classes).
Allowing the creation of new classes enables the existence of a hierarchy of
classes that simulates the class and subclass concept of the real world. The
new derived class inherits the members of the base class and also adds its own.
For example, a banking system would expect to have customers, of which we keep
information such as name, address, etc. A subclass of customer could be
customers who are students, where not only we keep their name and address, but
we also track the educational institution they are enrolled in.
Inheritance is
mostly useful for two programming strategies: extension and specialization.
Extension uses inheritance to develop new classes from existing ones by adding
new features. Specialization makes use of inheritance to refine the behavior of
a general class.
Polymorphism means that the same operation may behave
differently for different classes. The move
operation, for example, behaves differently for a pawn than for the in a chess
game. An operation is a procedure or
transformation that an object performs or is subject to. Right Justify, display, and move
are examples of operations. An implementation of an operation by a specific
class is called a method. Because an
OO operator is polymorphic, it may have more than one method implementing it,
each for a different class of object.
(or)
Polymorphism
allows an object to be processed differently by data types and/or data classes.
More precisely, it is the ability for different objects to respond to the same
message in different ways. It allows a single name or operator to be associated
with different operations, depending on the type of data it has passed, and
gives the ability to redefine a method within a derived class.
For example, given the student and business subclasses of customer
in a banking system, a programmer would be able to defi ne different getInterestRate()
methods in student and business to override the default
interest getInterestRate() that is held in the customer class.
While Java supports method overloading, it does not support operator overloading.
Encapsulation
The process, or
mechanism, by which you combine code and the data it manipulates into a single
unit, is commonly referred to as encapsulation. Encapsulation provides a layer
of security around manipulated data, protecting it from external interference
and misuse. In Java, this is supported by classes and objects.
Data Abstraction
Real-world
objects are very complex and it is very difficult to capture the complete
details. Hence, OOP uses the concepts of abstraction and encapsulation.
Abstraction is a design technique that focuses on the essential attributes and
behavior. It is a named collection of essential attributes and behavior
relevant to programming a given entity for a specific problem domain, relative
to the perspective of the user.
No comments:
Post a Comment