Skip to main content
improved code format
Source Link
Kilian Foth
  • 111k
  • 45
  • 302
  • 323
  • Composition is an Association

  • Aggregation is an Association

  • Composition is a strong Association (If the life of contained object totally depends on the container object, it is called strong association)

  • Aggregation is a weekweak Association (If the life of contained object doesn't depends on the container object, it is called weekweak association)

Example:

class Contained { public void disp() { System.out.println("disp() of Contained A"); } } public class Container { private Contained c; //Composition Container() { c = new Contained(); } //Association public Contained getC() { return c; } public void setC(Contained c) { this.c = c; } public static void main(String[] args) { Container container = new Container(); Contained contained = new Contained(); container.setC(contained); } } 
  • Composition is an Association

  • Aggregation is an Association

  • Composition is a strong Association (If life of contained object totally depends on container object it is called strong association)

  • Aggregation is a week Association (If life of contained object doesn't depends on container object it is called week association)

Example:

class Contained { public void disp() { System.out.println("disp() of Contained A"); } } public class Container { private Contained c; //Composition Container() { c = new Contained(); } //Association public Contained getC() { return c; } public void setC(Contained c) { this.c = c; } public static void main(String[] args) { Container container = new Container(); Contained contained = new Contained(); container.setC(contained); } } 
  • Composition is an Association

  • Aggregation is an Association

  • Composition is a strong Association (If the life of contained object totally depends on the container object, it is called strong association)

  • Aggregation is a weak Association (If the life of contained object doesn't depends on the container object, it is called weak association)

Example:

class Contained { public void disp() { System.out.println("disp() of Contained A"); } } public class Container { private Contained c; //Composition Container() { c = new Contained(); } //Association public Contained getC() { return c; } public void setC(Contained c) { this.c = c; } public static void main(String[] args) { Container container = new Container(); Contained contained = new Contained(); container.setC(contained); } } 

/*

  • Composition is aan Association

  • Aggregation is aan Association

  • Composition is a Strongstrong Association (If life of contained object totally depends on container object it is called strong association)

  • Aggregation is a weekweek Association (If life of contained object doesn't depends on container object it is called week association)

  • */

class Contained { public void disp() { System.out.println("disp() of Contained A"); } }

public class Container { private Contained c;

//Composition Example:

class Contained Container{ public void disp() { System.out.println("disp() of Contained A"); } } public class Container { private Contained c;  //Composition Container() { c = new Contained();   } 

//Association

  //Association public Contained getC() { return c;   }   public void setC(Contained c) { this.c = c;   } 

public static void main(String[] args) {

 public static void main(String[] args) { Container container = new Container();    Contained contained = new Contained();     container.setC(contained);   }  } 

}

}

/*

  • Composition is a Association

  • Aggregation is a Association

  • Composition is a Strong Association (If life of contained object totally depends on container object it is called strong association)

  • Aggregation is a week Association (If life of contained object doesn't depends on container object it is called week association)

  • */

class Contained { public void disp() { System.out.println("disp() of Contained A"); } }

public class Container { private Contained c;

//Composition

 Container() { c = new Contained(); } 

//Association

 public Contained getC() { return c; } public void setC(Contained c) { this.c = c; } 

public static void main(String[] args) {

 Container container = new Container();  Contained contained = new Contained();   container.setC(contained);   

}

}

  • Composition is an Association

  • Aggregation is an Association

  • Composition is a strong Association (If life of contained object totally depends on container object it is called strong association)

  • Aggregation is a week Association (If life of contained object doesn't depends on container object it is called week association)

Example:

class Contained { public void disp() { System.out.println("disp() of Contained A"); } } public class Container { private Contained c;  //Composition Container() { c = new Contained();   }   //Association public Contained getC() { return c;   }   public void setC(Contained c) { this.c = c;   }  public static void main(String[] args) { Container container = new Container();   Contained contained = new Contained();   container.setC(contained); }  } 
added 10 characters in body
Source Link
Pawan
  • 321
  • 3
  • 3

/*

  • Composition is a Association

    Composition is a Association

  • Aggregation is a Association

    Aggregation is a Association

  • Composition is a Strong Association (If life of contained object totally depends on container object it is called strong association)

    Composition is a Strong Association (If life of contained object totally depends on container object it is called strong association)

  • Aggregation is a week Association (If life of contained object doesn't depends on container object it is called week association)

    Aggregation is a week Association (If life of contained object doesn't depends on container object it is called week association)

  • */ class Contained { public void disp() { System.out.println("disp() of Contained A"); }

    */

    }

class Contained { public void disp() { System.out.println("disp() of Contained A"); } }

public class Container { private Contained c;

//Composition Container() { c = new Contained(); }

 Container() { c = new Contained(); } 

//Association public Contained getC() { return c; }

 public Contained getC() { return c; } public void setC(Contained c) { this.c = c; } 

public static void main(String[] args) { Container container = new Container(); Contained contained = new Contained(); container.setC(contained);

 Container container = new Container(); Contained contained = new Contained(); container.setC(contained); 

}

}

/*

  • Composition is a Association
  • Aggregation is a Association
  • Composition is a Strong Association (If life of contained object totally depends on container object it is called strong association)
  • Aggregation is a week Association (If life of contained object doesn't depends on container object it is called week association)
  • */ class Contained { public void disp() { System.out.println("disp() of Contained A"); } }

public class Container { private Contained c;

//Composition Container() { c = new Contained(); }

//Association public Contained getC() { return c; }

 public void setC(Contained c) { this.c = c; } 

public static void main(String[] args) { Container container = new Container(); Contained contained = new Contained(); container.setC(contained);

}

}

/*

  • Composition is a Association

  • Aggregation is a Association

  • Composition is a Strong Association (If life of contained object totally depends on container object it is called strong association)

  • Aggregation is a week Association (If life of contained object doesn't depends on container object it is called week association)

  • */

class Contained { public void disp() { System.out.println("disp() of Contained A"); } }

public class Container { private Contained c;

//Composition

 Container() { c = new Contained(); } 

//Association

 public Contained getC() { return c; } public void setC(Contained c) { this.c = c; } 

public static void main(String[] args) {

 Container container = new Container(); Contained contained = new Contained(); container.setC(contained); 

}

}

Source Link
Pawan
  • 321
  • 3
  • 3
Loading