Differentiate link aggregation and layout using source code

Is it possible to distinguish the ratio of composition and aggregation by reading the source code?

I tried to find some patterns and I listed them below.

I am taking an example from this site to explain what I consider a template

Structure

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 to differentiate

COMPOSITION (included)

  • Defined as a class field.

    • Example: [Engine e] Engine is defined as an e field of class Car
  • It is executed and assigned inside the class.

    • Example: [Engine e = new Engine ();] The engine is created inside the class

Aggregation (has a)

  • Defined as a class field

    • Example: [private Address address;] The address is defined as the address field of the Person class
  • Defines the side of the class.

    • : [ = ();] .
  • .

    • : [ = ();] Person.

?

, ?

+5
3

, ( , : " ", "" "" ).

, , Engine Car , , , ( ) Cars Engines Engine.

+1

( ), , "" / "", ; -)

?

, , , .

+1

- , , . . , , , . .

- , , , . . , , . "has-a".

, "". . , , . . , , , , .

, , , , , - .

Shortly speaking; yes, after reading the code, you can determine the type of relationship (composition and aggregation, but I'm not sure of the association) according to the definitions, and I think your differentiation patterns are correct.

0
source

All Articles