MS Rumi. Powered by Blogger.

Sunday 26 October 2014

Interview Question For Association, Composition and Aggregation in OOP

By Unknown  |  02:52 No comments

Explanation of  Association, Composition and Aggregation in OOP with examples (C++)

Association

C++ Implementation of Association
It is the relationship between two or more objects, where every objects have its own life cycle and there is no owner of these objects. Let's have an example of association between student and tutor. One student can teach by one tutor, many student can teach by one tutor or many tutor can associate with a single student and also many student associate with many teacher or tutor. Here student and tutor are the objects and both have no owner. They can build and delete independently. Association is represented by a solid line.

Generalization

In object oriented modal some classes may have common characteristic we extract there common feature into new class and inherit original classes from this new class. For example we have two classes Teacher with characteristic name, age, sex, birthday, class, salary and job title  Student with characteristic name, age, sex, birthday, class, fee and GPA. Both classes have some common characteristics so we extract these feature in new class called Person.
Generalization

Specialization 

If we want to add new class to a existing modal, find the similar characteristic into model but some part of behavior of new class is different are restricted for that we can use specialization. For example in previous table we had Person as parent class and teacher and student as child class now we want to add adult class with same characteristics but here age should be more then 18.
Specialization

Class Association

Class association is implemented in term of inheritance implemented generalization or specialization relationship between the classes in case of public inheritance it implement "Is A" relationship and in private inheritance "Implemented in term of" relationship. Member of base class are available to child class.

Object Association

Its interaction of one class object with a objects of other classes.

Aggregation

It is specialize form of association. In this an object may contain collection of other objects, relationship between container and contained object is known as aggregation. Here every objects have their own life cycle but they are owned by other class and these objects can't be owned by any other class. Lets take an example of  Room, here room is parent class and its child classes are chair, table, bad and mirror. If any of child class is removed it will not affect other class. It is represented by blank diamond.
Some important point of aggregation
  • Relationship between objects are "Has A"
  • Every Object have independent life
  • Child Parent relationship

Commposition

It is specialize form of Aggregation. In this an object maybe compose of other smaller objects. Its the relation of "Part and Whole". It also known as Has A  relationship and it is represented by filled diamond. In this every child class does not have life cycle they are dependant on parent class. If parent class is deleted all child class will also deleted. Lets have an example, here Human body and body parts have relationship.
Some important points of commpositon
  • Strong Relationship
  • Only Parent have independent life cycle
  • Parent child relationship

Author: Unknown

Hello, I am Author, thanks for visiting my blog. Bookmark this....

0 comments:

E-mail Newsletter

Sign up now to receive breaking news and to hear what's new with us.

Recent Articles

TOP