Friday, January 29, 2010

OOPS

COMPOSITION
-----------------------------
Imagine a software firm that is composed of different Business Units (or departments) like Storage BU, Networking BU. Automobile BU. The life time of these Business Units is governed by the lifetime of the organization. In other words, these Business Units cannot exist independently without the firm. This is COMPOSITION. (ie the firm is COMPOSED OF business units)

Mentioned by HAS-A relationship. It describes the member field or an object.
The part(s) are usually expected to “live” and “die” with the whole



AGGREGATION
-----------------------------
Consider a Car manufacturing unit. We can think of Car as a whole entity and Car Wheel as part of the Car. (at this point, it may look like composition..hold on) The wheel can be created weeks ahead of time, and it can sit in a warehouse before being placed on a car during assembly. In this example, the Wheel class's instance clearly lives independently of the Car class's instance. Thus, unlike composition, in aggregation, life cycles of the objects involved are not tightly coupled.


Mentioned by HAS-A relationship. It describes the member field or an object.


ASSOCIATION
-----------------------------
The software firm may have external caterers serving food to the employees. These caterers are NOT PART OF the firm. However, they are ASSOCIATED with the firm. The caterers can exist even if our software firm is closed down. They may serve another firm! Thus the lifetime of caterers is not governed by the lifetime of the software firm. This is typical ASSOCIATION. (This is the simplest relationship between objects)

Composition Vs Aggregation..
-----------------------------
Usually, composition means that the lifetime of the contained object is bounded by that of the container, whereas aggregation is a reference to an object which may exist independently.


Inheritance
------------------------

Inheritance is used to express “is-a” or “kind-of” relationships. A car is a vehicle. A boat is a vehicle. A submarine is a vehicle. In OOP, the Vehicle base class would provide the common behaviors of all types of vehicles and perhaps delineate behaviors all vehicles must support. The particular subclasses (i.e., derived classes) of vehicles would implement behaviors specific to that type of vehicle. The main concepts behind inheritance are extensibility and code reuse.

Composition
-----------------------------

In contrast to inheritance, there is also the notion of a “has-a” relationship. This relationship is created by using composition. Composition, which is sometimes referred to as aggregation, means that one object contains another object, rather than inheriting an object’s attributes and behaviors. Naturally, a car has an engine, but it is not a kind of engine.

1 comment:

Anonymous said...

I would like to exchange links with your site sankargreet.blogspot.com
Is this possible?