What is Object Oriented Programming?
It is the style of programming in which 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 (Object Oriented Programming)
An object that holds another object within its data block exhibits containment (HAS-A) relationship with that object which is the following two types:
- 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.
- 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.
- 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.
- An object that holds another object within its data block exhibits a containment (HAS-A) relationship with that object which is the 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 lifetime.
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 hold the identity of the inner object and allows it to control its own lifetime.
Ex: In Fig 4.(b) Room has a identity(Name,age,address) of guest and guest have its own life time
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.
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.
An object of derived class exhibits inheritance (IS-A) relationship with its base class which is of the following two types: Realization: It is a type of inheritance in which the base class is abstract but the derived class is not abstract.
Specialization: It is a type of inheritance in which base class and derived class both non-abstract.