Skip to content

Instantly share code, notes, and snippets.

@al26p
Last active January 18, 2019 17:07
Show Gist options
  • Save al26p/d5a10731afba51b5cf047f5ab6593624 to your computer and use it in GitHub Desktop.
Save al26p/d5a10731afba51b5cf047f5ab6593624 to your computer and use it in GitHub Desktop.
/*
* Example of using aggregation.
*
* Here if a Telephone is deleted, the screen can still exist.
*/
Class Ecran;
Class Telephone{
Ecran screen;
public void Telephone(Ecran screen){
this.screen = screen;
}
}
main(){
Ecran screen = new Ecran();
Telephone tel = new Telephone(screen);
}
/*
* Example of using composition
*
* Here if a Telephone, its screen will be destroyed by Java's garbage colelctor.
* Ecran cannot exist without Telephone.
*/
Class Ecran;
Class Telephone{
Ecran screen;
public void Telephone(){
this.screen = new Screen();
}
}
main(){
Telephone tel = new Telephone();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment