Thursday, February 10, 2011

Basic Characteristics of OOP


Basic Characteristics of Object-Oriented Languages
Objects:
 An object represents an individual, identifiable item, unit, or entity, either real or abstract, with a well-defined role in the problem domain.  An object may be
Ø  Tangible Things    as a car, printer, ...
Ø  Roles                     as employee, boss, ...
Ø  Incidents               as flight, overflow, ...
Ø  Interactions           as contract, sale, ...
Ø  Specifications       as colour, shape, …
Ø  Elements of Computer-
             User environment   as Windows, menu,……
In object-oriented programming, problem is analyzed in terms of objects. Programming object should be chosen such that they match closely with the real world objects. Each object contains data and code to manipulate the data. It can be defined as
Object = Data + Methods or functions

Classes:
  A class may be defined as a collection of similar objects. In other words, it is a general name for all similar objects. For example, mango, apple, banana all may be described under the common name fruits. Thus, fruits is class name for objects like mango, apple, and banana. In fact, a class is user defined data type and behaves like the built-in data types of programming languages. A class serves as a blue print or a plan or a template. It specifies what data and what functions will be included in objects of that class. Once a class has been defined, we can create any number of objects belonging to that class. If fruits has been defined as a class, then statements
  fruits mango;
  fruits apple;
    will create objects mango and apple belonging to the class fruits. This is similar to creating variables of built-in data types like     int a;

Inheritance:
    Inheritance is the process by which objects of one class acquires the properties of objects of another class. Inheritance allows to create classes which are derived from other classes, so that they automatically include its "parent's" members, plus its own. Thus, a class can be divided into a number of sub classes. The derived classes are known as sub classes and original classes are base classes. For example, a class of animals is divided into mammals, amphibians, insects, birds and so on. The class of vehicles is divided into cars, trucks, buses and motor cycles. Each sub class shares common characteristics with the class from which it is derived. Cars, trucks, buses and motorcycles all have wheel and a motor; these are the defining characteristics of vehicles. In addition to these shared characteristics, each sub class also has its own characteristics: buses have seats for many people while trucks have space for heavy loads.
             The concept of inheritance provides the idea of reusability, means additional features can be added to an existing class without modifying it. In above example, the class ‘buses’ can be inherited from base class ‘vehicles’. Then, all features of vehicles class are also of class ‘buses’. Thus, we do not need to mention common properties to class ‘buses’. The only special features of buses are included in class ‘buses’. The common properties are shared from class ‘vehicles’. Thus,
 features of class ‘buses’= special features of class ‘buses’+ common features of
                                             class ‘vehicles’
Reusability:
    Object-oriented programming uses concept of reusability. The reusability implies the reuse of existing code in another program without modification to it. The concept of inheritance provides an idea of reusability in OOP. Once a class has been written, created and debugged, it can be used in another program. A programmer can use an existing class and without modifying it, add additional features and capabilities to it. This is done by deriving a new class from existing one. The new class will inherit the capabilities of the old one but is free to add new features of its own.

Creating new data types:
     Object-oriented programming gives the programmer a convenient way to construct new data type. Creating a class in object oriented programming can be considered as creating new data types. As we can define different variables of built-in data types like int, float, char, we can create various objects of classes in similar manner. For example, if man is class name defined in the program, then
 man ram;
 will create an object ram of type man. Thus, man is user defined data type. A class name specifies what data and what functions will be included in objects of that class.

Polymorphism and overloading:
  The property of object-oriented programming polymorphism is ability to take more than one form in different instances. For example, same function name can be used for different purposes. Similarly, same operator can be used for different operations. The overloading is a kind of polymorphism. If an operator exhibits different behaviors in different instances, then it is known as operator overloading. The type of behavior depends upon the type of the data used in the operation. Similarly, if a same function name is used to perform different types of tasks, then it is known as function overloading. The task to be performed by the function is determined by number of arguments and type of arguments.    

No comments:

Post a Comment