Week 6 Flashcards
A general relationship that describes an activity between 2 classes
Association
How are associations denoted? How do the 2 classes relate?
A straight line arrow and direction. They relate through their objects.
To communicate between each other, 2 classes must have a link between them. What is this link represented by?
Association.
What are 2 form of association?
Aggregation and composition
A relationship where an objects owns a collection of other identical objects
Aggregation, also known as a has-a relationship
What are some examples of aggregations?
Professor has many students, hotel has many suites. One way, reverse not possible
T/F - An aggregation relationship is represented by a field in the aggregating class
True
Aggregated class
public class Name {}
Aggregating class
public class Student {
private Name name;
private Address address;
…
}
Relationship where a class contains other references to other classes
Composition (has-a relationship)
IE. Room has a door, Car has a wheel
T/F - Composition is a special cast of aggregation
True
In __________ a child can exist independently of the parent, in ___________ the child cannot exist independent of the parent
Aggregation, composition
Composition vs Aggregation, types of association
Composition: Strong association
Aggregation: Weak association
Inheritance has what type of relationship?
is-a relationship
the ___class is a specialization of the _____class, and has characteristics of it
subclass, superclass
Can a subclass be treated like a parent type?
Yes. A motorcycle is-a vehicle. A car is-a vehicle.
Can every class be inherited?
No, final classes cannot.