What is Object Oriented Programming ?

It is style of programming in which a large application software is implemented in terms of independently programmable units of “data” (in the form of fields, often known as attributes) and “operations” or “codes” (in the form of procedures, often known as methods) called objects.

BASIC ELEMENTS OF OOP

An object that holds another object within its data block exhibits containment (HAS-A) relationship with that object which is a following two types:

  1. Every object has a class that specifies a set of variables(fields), which defines the data(state) stored in the object and a set of functions(methods), which defines the operations(behavior) supported by the object.
  2. An object is created (activated) from a class through instantiation in which first a memory block allocated for storing the values of the variables specified by the class and then a special function called constructor, specified by the class is called for initializing those values.
  3. Every object has a unique identity and when a function specified by a class is called on its objects the identity of this object is implicitly passed to the implementation of that function.
  4. An object that holds another object within its data block exhibits containment (HAS-A) relationship with that object which is a following two types:
    • Composition: It is a type of containment in which the outer object holds the entire data of the inner object and controls its life time.
      object oriented programming

      Fig.4(a)

      Ex: In Fig 4.(a)Hotel has a Room(or hotel contains room), Room does not have its own life time.

    • Aggregation: It is a type of containment in which the outer objects holds the identity of the inner object and allows its to control its own life time.
      Aggregation

      Fig.4(b)

      Ex: In Fig 4.(b) Room has a identity(Name,age,address) of guest and guest have its own life time

  5. A derived class can be defined as an extension (subclass) of an existing base (super) class. To specify additional variables and functions or to provide new implements for its existing functions.
  6. A non-instantiable abstract class can be defined to specify a set of pure(unimplemented) functions called an interface which can be implemented by its non-abstract (instantiable) derived classes.
  7. An object of derived class exhibits inheritance (IS-A) relationship with its base class which is of following two types:
    • Realization: It is a type of inheritance in which the base class is abstract but the derived class is not abstract.

      Realization

      Fig.7(a)

    • Specialization: It is a type of inheritance in which base class and derived class both non-abstract.

      Specialization

      Fig.7(b)

 

Leave a Reply