Last active
January 18, 2019 17:07
-
-
Save al26p/d5a10731afba51b5cf047f5ab6593624 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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