Roadmap › OOP Concepts in C# › Module: Relationships and Design
Lessons in this course (15)

12. Association, aggregation and composition

Intermediate★ Must knowLesson 12 of 15
RelationshipMeaningLifetimeExample
Association"uses" / knows aboutIndependentTeacher ↔ Student
Aggregation"has-a", weak ownershipPart can exist without wholeDepartment has Employees
Composition"owns-a", strong ownershipPart dies with wholeOrder owns OrderLines; House owns Rooms
Inheritance"is-a"—Car is a Vehicle
csharp
public class Order               // composition: lines are created and owned by the order
{
    private readonly List<OrderLine> _lines = [];
    public void Add(string sku, int qty) => _lines.Add(new OrderLine(sku, qty));
}

public class Department          // aggregation: employees exist independently
{
    public List<Employee> Members { get; } = [];
}