♠ Posted by Unknown in Fundamentals,OOPS at 04:26
Object-Oriented Programming&Characteristics
Object-oriented
programming (OOP) is a powerful way to approach the task of programming. At
each critical point in the evolution of programming, a new approach was created
to help the programmer handle increasingly complex programs. OOP takes the best
of the ideas embodied in structured programming and combines them with powerful
new concepts that allow you to organize your programs more effectively.
Object-oriented programming encourages you to decompose a problem into its
constituent parts.
Each
components becomes a self-contained object that contains its own instruction
and data that relate to that object. In this way, complexity is reduced and
data that relate to that object. In this way, complexity is reduced and the
programmer can manage larger programs.
All OOP
languages, including C++, share three common defining traits: Encapsulation,
Polymorphism, and Inheritance.
Characteristics:
- ENCAPSULATION/DATA
ABSTRACTION/DATA HIDING :-
Encapsulation
is that mechanism that binds together code and the data it manipulates, and
keeps both stage from outside interference and misuse. In an object-oriented
language, code and data can be combined in such a way that a self-contained
“black-box” is created. When code and data are linked together in this fashion,
an object is created. In other words, an object is the device that supports
encapsulation.
Within an
object, code, data, or both may be private
to that object or public. Private
code or data is known to and accessible only by another part of the
object. That is, private code or data
cannot be accessed by a piece of the program that exists outside the object.
When code or data is public, other parts of your program can access it even though
it is defined within an object.
For all
intents and purposes, an object is a variable of a user-defined type. It may
seem strange that an object that links both code and data can be thought of as
a variable. However, in Object-Oriented programming, this is precisely the
case. Each time you define a new type of object, you are creating a new data
type. Each specific instance of this data type is a compound variable.
- POLYMORPHISM :-
Polymorphism
(from the Greek, meaning “many forms”) is the quality that allows one name to
be used for two or more related but technically different purposes. As it
relates to OOP, polymorphism allows one name to specify a general class of
actions. For example, in C, which goes not significantly support polymorphism,
the absolute value action requires three distinct function names: abs(),
labs(), and fabs(). These functions
compute and return the absolute value of an integer, a long integer, and a
floating point value respectively. However, in C++ , which supports polymorphism,
each function can be called by the same name such as abs(). The type of data
used to call the function determines which specific version of the function is
actually executed. As you will see, in C++ it is possible to use one function
name for many purposes. This is called function overloading.
Polymorphism
can be applied to operators, too. Virtually all programming languages contain a
limited of polymorphism as it relates to the arithmetic operators. For example,
in C, the + sign is used to add integers, long integers, characters, and
floating-point values. In these cases, the compiler automatically knows which
type of arithmetic to apply. In C++, you can extend this concept to other types
of data that you define. This type of polymorphism is called Operator
Overloading.
- INHERITANCE/REUSABILITY/Extendibility:-
Inheritance
is the process by which one object can acquire the properties of another. More
specifically, an object can inherit a general set of properties to which it can
add those features that are specific only to itself. Inheritance is important
because it allows an object to support the concept of hierarchical
classification. In each case, the child class inherits all those qualities
associated with the parent and adds to them its own defining characteristics.
Without the use of ordered classifications, each object would have to define
all characteristics that relate to it explicitly. However , through
inheritance, it is possible to describe an object by stating what general class
(or classes) it belongs to along with those specific traits that makes is
unique.
- Object & Classes :-
Objects are
the basic Run-Time entities in an object Oriented System. They may represent a
person, a place, a bank account. A table of data or any item.
Programming
problem is analyzed in terms of objects and the nature of communication between
them. Objects take up space in the memory and have an associated address like a
record in PASCAL or a structure in C.
When a
program is executed the objects interact by sending messages to one another for
example if “Customer” and “Account” are tow objects in a program, then the
customer object may send a message. It is sufficient to know the type of
message accepte3d and the type of response returned by the objects.
We just mentioned that objects
contain data and code to manipulate the data. the entire set of data and code
of an object can be made a user-defined data type with the help of a class.
Objects are variables of the type class. Each objects is associated with the
data of type class with which they are created. A class is has a collection of
objects of similar type. Classes are user defined data types and behave like
the built-in types of a programming language. If “Fruit” has been defined as a
class :
Fruit Mango;
Will create
an object Mango belonging to the class “Fruit”.
- Dynamic Binding :-
Binding
refers to the linking of a procedure call to the code to be executed in
response to the call. Dynamic binding means that the code associated with a
given procedure call is not known until the time of the call at run-time the
dynamic type of that reference.
- Message Passing :-
An object
Oriented Program consists of a set of objects that communicate with each other.
The process of programming in an object oriented language. Therefore involves
the following basic steps:
- Creating classes that define
objects and their behavior.
- Creating objects from class
definitions and establishing communication among objects.
Objects
communicate with one another by sending and receiving information much the same
way as people pass messages to one another.
A message
for an object is a request for execution of a procedure, and therefore will
invoke a function in the receiving object that generate the desired result.
Objects
have a life cycle. They can be created and destroyed. Communication with an
object is feasible as long as it is alive.
- Abstract Class :
An Abstract
class is on that is not used to create objects. An abstract class is designed
only to act as a base class (to be inherited by other classes). It is a design
concept in program development and provides a base upon which other classes may
be built.
0 comments:
Post a Comment