OOP Midterm Flashcards
Uses-a types (3)
Dependency
Association
Direct Association
Has-a types (2)
Aggregation
Composition
Is-a types (1)
Inheritance
Implements-a types (1)
Interface Implementation (realization)
Dependency
transient relationship between two classes. Implementation of class A that uses class B does not affect class A definition
Class B is unaware of the existence of the class A (Asymmetry)
(Minimize this relationship to reduce coupling)
Association
relationship between Class A and Class B last as long as both object live at runtime. One class is owned by the object of another class
dependency example
A method of class Sequence uses a Stack class to verify palindrome. A student enrollment class uses a student class in its method
i.e. A method of class A is passed as parameter of class B and returns a value of class B.
association example
A teacher class has a method to assign students to a class while students can (or can not) specify which teacher is teaching their class
i.e. class A has an attribute that is class B
cardinality
Defines multiplicity between objects (one-to-one, one-to-many…)
direct association
A strong connection between classes where both classes are generally aware of each other and have direct references or attributes that link them
direct association example
A teacher class where each student is defined a specific teacher and each teacher has a direct reference to their student. Both classes are aware of each other
association subtypes
aggregation
composition
A child class that cannot exist independently of its parent class
composition example
Class car has a class Engine. Since Car owns Engine, it controls the lifetime of this class meaning once Car is destroyed, so is Engine
aggregation
Child class is independent of its parent class meaning its a standalone and unidirectional class that can exist independent of it’s parent class. Association is unidirectional.
aggregation example
Class University aggregates Class department objects. The department objects can exist independently of the university
i.e. Class A contain objects of class B over period of time. Both objects survive individually
restricted form of aggregation
composition