One Pager Cheat Sheet
- By the end of this lesson, you will understand key
object-oriented programming
terms like association, aggregation, and composition and have a clear understanding of how to create diagrams representing these relations among classes. - Association is the relationship between two objects, which can be of the same or different type, and is usually represented as either a composition or an aggregation.
- Composition is a form of association in which an object's life is bound to that of its containing object, and all objects inside it die when the main object is deleted.
- Aggregation allows for the referencing of other objects in a container object, without affecting the life cycle of the referenced objects.
Composition and aggregation are two forms of association, with the main difference being that composition involves a stronger form of relationship than aggregation, and compositied objects cannot be changed from the referrer, while aggregated objects can be removed or replaced.
- The relationship between two objects is
association
, meaning that they have some kind of connection with no logical dependency enforced. - Object typecasting is the process of converting one primitive data type to another or one class to another compatible class in the same type hierarchy, which can be done automatically or by manually upcasting or downcasting.
- The
Object
class in Java is the parent of all classes and provides various useful methods such asgetClass()
,hashCode()
,equals()
andtoString()
that are inherited by all classes and can be referred to by a reference variable even if the type of the object is unknown. waitForAll
is not a method that is provided within Java'sObject
class.- UML provides a standard pictorial language for specifying and visualizing the objects and relationships of object-oriented designs, allowing efficient collaboration among software system collaborators.
- UML can be used to create Class Diagrams and
Object Diagrams
visually, the latter having underlinings under the Object's name. Relationships
in UML are represented with lines and arrows that define the interactivity of objects and classes, such as association, inheritance, aggregation and composition.- The
Player
andSaveFile
classes can be linked by anassociation
relationship, which can be indicated through multiplicity values near the related class. - Aggregation is shown in UML by an open diamond and can be demonstrated with the example of a car with multiple Passengers and one Driver, showing that their lives are not bound to the car.
- Objects can have a bound relationship, which is displayed as a
filled-in diamond shape
in UML diagrams, dubbed the composition arrow. - Using
generalization
to show inheritance between classes, we can use a simple arrow to represent the relationship betweenToyota Corolla
andFord Explorer
as children of a more generalCar
class. - A class
implements
an interface torealize
the functions defined by the interface, as shown by the example ofCar
implementing
Drivable
. - UML diagrams can provide a valuable tool when deciding between
aggregation
andcomposition
when usingOOP
, helping to visualize and understand relationships in code.