uml - Differentiate aggregation and composition relationship using source code -


is possible differentiate between composition , aggregation relationship reading source code?

i tried find patterns , have listed them below.

i taking example this site explain assume pattern

composition

enter image description here

 public class engine {     . . .  }  public class car {    engine e = new engine();     ....... } 

aggregation

enter image description here

public class address { . . . }  public class person {    private address address;    public person(address address)    {      this.address = address;    }    . . . } 

i find these patterns differentiate

composition (is part of )

  1. defined field of class.

    • example: [engine e] engine defined field e of class car
  2. instantiated , assigned within class.

    • example: [engine e = new engine();] engine instantiated inside class

aggregation (has a)

  1. defined field of class

    • example: [private address address;] address defined field address of class person
  2. instatiated out side class

    • example: [address address = new address();] address instatiated outside person.
  3. assigned in constructor sending instance argument constructor.

    • example: [person person = new person(address);] instance of address passed argument through constructor , assigned in constructor of class person.

can consider these differentiate aggregation , composition relation?

are there more constraints used differentiate?

not really, because there's not unique way implement each kind of association (in fact, problem have 3 kinds of associations, "normal associations", "aggregations" , "compositions").

if language has pointers try guess if engine defined in car pointer programmer wrote piece of code suggesting softer relationship (aggregation or association) between cars , engines since removing car not imply losing engine object.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -