Bifalgorithm post · Computer science one · Composition
How does composition model objects made up of other objects?
How does composition model objects made up of other objects? (Computer science one · Composition) — "Another important concept when designing classes is compos…
Ideas in this flowchart
- Composition in class design
- Composition makes an object out of other objects.
- An object can own an instance of another object.
- The Student class owns two instances of the String class.
- The Student class can be extended with a date of birth.
- A date of birth contains multiple pieces of data, such as a year, month, date, time, or locale.
- It is generally best to use the language's existing date and time facilities instead of designing a custom class.
- Java 8 introduced the java.time package with improved date and time classes.
- The LocalDate class can model a date of birth.
- Example declaration: private LocalDate dateOfBirth;