Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

association vs aggregation vs inheritance vs composition

associations, aggregations, and inheritance


Hi,

I always get confused with these three structural relationship terms used heavily in java.

a.associations
b.aggregations
c.inheritance
d. compostion

What are the practical uses of them. Why we need them and which one to use in which case. Specifically association vs aggregation is more confusing to me. when to use aggregation and when to use plain association in the UML representation. what is the practical difference between uni and bi directional association and what are the various symbols used to represent them in UML. How to prepare association matrix of all the objects with each other involved during analysis phase. what are the static and dynamic aspects of abstraction?
Please advise
ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

I can relate better now and I see thick/filled in/black diamond arrow as the composition relationship is thick where as aggregation it is open/white/thin arrow as relationship is thin and open extended triangle for inheritance pointing towards base class(may be because inheritance one form of extension of base class). In the shoe example what is the direction( it the Person contains the Shoe right even though it could be external and not as restrictive as Person, Heart).

Also what is uni and bi directional association.

what are the static and dynamic aspects of abstraction.

How the genaralisation is related to inheritance and 'is a' relationship'

So composition, aggregation is related to to 'has a' relationship right.

Association could be both 'is a' as well 'has a'.

How 'association' is different from 'dependency'

I read inheritance implies it is relationship between the classes but not between objects. And makes not sense to apply multiplicity on inheritance.
Not sure what exactly what above two lines means? All others(like association, composition, aggregation etc) are relation between objects but not classes?

please advise
Avatar of dpearson
dpearson

Glad this is making more sense now.  You have about 10 new questions - all of which are big topics.  I can't take them all on in this one question - we'll never get to the end :)

I'd suggest breaking some of those out into new questions.

This one:
Also what is uni and bi directional association.

Is simple enough to answer here.

Unidirectional means A has a reference to B.  But B does not have a reference to A.
Bidirectional means A has a reference to B AND B has a reference to A.

Doug
How the genaralisation is related to inheritance and 'is a' relationship'

HashMap 'is a' Map .  

Map is a generalised form of HashMap .
Avatar of gudii9

ASKER

what is 'has a' in this context. please advise
"has a" means the parent object contains a reference to the child (so it's using composition or aggregation).

E.g.
   Person Has-A Leg
   House Has-A Door

Unlike "is a" which means "is a kind of" (so we're talking inheritance).

E.g.
    Teacher Is-A Person
    Child Is-A Person

Doug
Avatar of gudii9

ASKER

In the java world inheritance means both 'Extends'(class A extends class B) and 'implements'(classA implements interfaceB right.

How the composition or agregation of parent object containing reference to child represented in java world(not in UML world)
Please advise
In the java world inheritance means both 'Extends'(class A extends class B) and 'implements'(classA implements interfaceB right.

Yes.  If you want to be more precise then "extends" is "implementation inheritance".  While "implements" is "interface inheritance".

How the composition or agregation of parent object containing reference to child represented in java world(not in UML world)

Just a class with a reference to an object:

// Composition:
// People have legs and if you delete the person, the legs are deleted as well.
public class Person {
     private Leg m_LeftLeg = new Leg() ;
     private Leg m_RightLeg = new Leg() ;
}

// Aggregation:
// Employees have supervisors.  But if you delete the employee the supervisor remains.
public class Employee {
      private Supervisor m_MyBoss ;
}

Doug
Avatar of gudii9

ASKER

so composition and aggregation we are talking within the class where as implementation inheritance/interface inheritance" we are talking about interaction of a class with outside entity(class or interface ) right?

so be a composition and aggregation or  implementation inheritance or interface inheritance everything comes under association right since there is relationship?

Please advise
so composition and aggregation we are talking within the class where as implementation inheritance/interface inheritance" we are talking about interaction of a class with outside entity(class or interface ) right?

so be a composition and aggregation or  implementation inheritance or interface inheritance everything comes under association right since there is relationship?

Yes that's all correct.

Doug