Advanced
minutes
Object Relationships Terminology
Overview of object relationship modeling concepts in this chapter.
Last updated:
Object Relationships Terminology Reference
This reference provides an overview of object relationships terminology you'll encounter in this chapter. Use it as a quick lookup guide.
Relationship Types
| Term | Definition | Example |
|---|---|---|
| Composition | "Has-a" relationship where part cannot exist without whole | Car has Engine, engine destroyed with car |
| Aggregation | "Has-a" relationship where part can exist independently | Department has Professors, professors can outlive department |
| Association | "Uses-a" relationship between independent objects | Doctor treats Patients |
| Dependency | One class uses another temporarily | Function parameter, local variable |
| Inheritance | "Is-a" relationship, derived class extends base | Dog is-a Animal |
Composition
| Term | Definition | Example |
|---|---|---|
| Part-whole Relationship | Component is part of larger whole | Engine is part of Car |
| Lifetime Dependency | Part's lifetime bound to whole's lifetime | Part created/destroyed with whole |
| Exclusive Ownership | Whole exclusively owns the part | Part belongs to one whole only |
| Member Object | Part stored as member variable | class Car { Engine m_engine; }; |
| Initialization in Constructor | Part initialized when whole is constructed | Member initializer list |
Aggregation
| Term | Definition | Example |
|---|---|---|
| Shared Relationship | Part can be shared among multiple wholes | Professor can be in multiple Departments |
| Independent Lifetime | Part can exist before and after whole | Professor exists after Department closed |
| Reference or Pointer | Whole holds reference/pointer to part | class Department { std::vector<Professor*> m_members; }; |
| Weak Ownership | Whole doesn't control part's lifetime | Part managed elsewhere |
| Container Relationship | Collection of independent objects | Team has Players |
Association
| Term | Definition | Example |
|---|---|---|
| Loose Coupling | Objects interact but remain independent | Doctor uses Patient records |
| Bidirectional Association | Both objects reference each other | Student knows Course, Course knows Students |
| Unidirectional Association | One object references another | Customer places Order |
| Multiplicity | Number of objects involved in relationship | One-to-one, one-to-many, many-to-many |
| Navigation | Direction relationship can be traversed | Student to Courses vs Courses to Students |
Ownership Models
| Term | Definition | Example |
|---|---|---|
| Exclusive Ownership | One object owns resource, uses value semantics | Composition with member object |
| Shared Ownership | Multiple objects share ownership | std::shared_ptr for aggregation |
| Non-owning Reference | Object refers but doesn't own | Raw pointer, reference, std::weak_ptr |
| Transfer of Ownership | Ownership moves from one object to another | std::unique_ptr with std::move |
| Observer Pattern | Non-owning reference to notify changes | Weak pointers to observers |
Implementation Strategies
| Term | Definition | Example |
|---|---|---|
| Value Semantics | Object directly contains part | class Car { Engine m_engine; }; |
| Reference Semantics | Object holds pointer to part | class Car { Engine* m_engine; }; |
| Smart Pointer Ownership | Using smart pointers to manage lifetime | std::unique_ptr<Engine> for composition |
| Container of Pointers | Collection holding pointers to objects | std::vector<Professor*> for aggregation |
| Initialization List | Initializing members in constructor | : m_engine{cylinderCount} |
Multiplicity
| Term | Definition | Example |
|---|---|---|
| One-to-One | Each object relates to exactly one other | Person has one Passport |
| One-to-Many | One object relates to many others | Mother has multiple Children |
| Many-to-One | Many objects relate to one | Multiple Students have one Teacher |
| Many-to-Many | Multiple objects on both sides | Students enroll in multiple Courses |
| Optional Relationship | Relationship may or may not exist | Person may have zero or one Spouse |
Dependency Management
| Term | Definition | Example |
|---|---|---|
| Tight Coupling | Strong dependency between classes | Hard to change one without affecting other |
| Loose Coupling | Minimal dependency between classes | Classes interact through interfaces |
| Dependency Injection | Passing dependencies as parameters | Constructor takes interface pointer |
| Interface Segregation | Depending on interface not implementation | Virtual base class for loose coupling |
| Forward Declaration | Declaring class without full definition | class Engine; in header |
Lifecycle Management
| Term | Definition | Example |
|---|---|---|
| Construction Order | Order members are initialized | Members initialized in declaration order |
| Destruction Order | Order members are destroyed | Reverse of construction order |
| RAII | Resource acquired in constructor, released in destructor | Automatic resource management |
| Lazy Initialization | Delaying object creation until needed | Create on first use |
| Two-phase Initialization | Separate construction and initialization | Constructor + init() method |
Design Patterns
| Term | Definition | Example |
|---|---|---|
| Composite Pattern | Tree structure with uniform interface | File system with files and folders |
| Adapter Pattern | Wrapping object to provide different interface | Legacy class adapter |
| Facade Pattern | Simplified interface to complex subsystem | High-level API hiding complexity |
| Proxy Pattern | Surrogate controlling access to object | Lazy loading, access control |
| Decorator Pattern | Adding behavior by wrapping object | Dynamic feature addition |
How did you find this lesson?
Your rating helps us improve the content.
Create an account to track your progress and access interactive exercises. Already have one? Sign in.
Object Relationships Terminology - Quiz
Test your understanding of the lesson.
6 questions
~5 min expected
60% to pass
Lesson Discussion
Share your thoughts and questions
💬
No comments yet. Be the first to share your thoughts!