logoNEURAL COOK
SearchAll PostsTagsNotesAuthor
logoNEURAL COOK

A posts created with Next.js and Tailwind.css

Explore

  • All posts
  • Notes
  • Snippets
  • Tags
  • RSS feed

Connect

instagramtwitterfacebookyoutubelinkedinmailgithub

© 2026 VIKI. All rights reserved.

Built with
Contents
60-Day LLD & Machine Coding Mastery Roadmap
The Four Pillars of OOPComposition, Asociation & AggregationDatabase locking / atomic updates
Don't Repeat Yourself (DRY) PrincipleKeep it Simple, Stupid (KISS) PrincipleYou Aren't Gonna Need It (YAGNI) Principle
Design a Library Management System (LMS)Design a Parking LotVending Machine
D : Dependency InversionI : The Interface Segregation PrincipleL : The Liskov Substitution PrincipleO : The Open/Closed PrincipleS : The Single Responsibility Principle
UML Activity Diagrams: Modeling Process and WorkflowUML Class Diagrams: Static Structure ModelingUML Sequence Diagrams: Modeling Dynamic InteractionsUse Case Diagrams: Functional Requirement Modeling
Low Level Design

Composition, Asociation & Aggregation

3 min read
On this pageAssociation
AssociationAggregationCompositionComposition vs InheritanceHow to choose ?
PropertyAssociationAggregationComposition
MeaningObjects are relatedWhole groups independent partsWhole strongly owns parts
OwnershipNot impliedWeak / shared or independentStrong
Part can exist independently?Usually yes; no lifecycle claimYesConceptually tied to the whole
Part can be shared?Yes, if allowedCommonly yesGenerally no simultaneous ownership by multiple wholes
UML notationPlain line or arrowHollow diamondFilled diamond

# Association

Two objects have a relationship, but neither necessarily owns the other. It says that one object knows about, refers to, or interacts with another object.

# Aggregation

It is a more specific kind of association. It represents a whole-part relationship, but the parts can exist independently of the whole. One object groups or references other objects, but those objects can exist independently and may be shared.

Use it when:

  • The whole groups parts.
  • The parts have an independent lifecycle.
  • The parts may be shared or reassigned.
  • The distinction from ordinary association adds useful meaning.

UML aggregation has relatively weak, often ambiguous semantics. Many designs use an ordinary association instead.

# Composition

Composition is a relationship where one object is made up of, or owns, other objects that help form it. So instead of making one giant class do everything, ==we build a larger object using smaller objects, each with its own responsibility==.

The filled diamond *-- indicates composition

composition does not mean an object must be deleted whenever its parent is deleted in every implementation. It communicates strong ownership in the domain model. Actual deletion and persistence behavior depend on the requirements

# Composition vs Inheritance

Composition means “has-a” or “is made of”, whereas Inheritance means “is-a”

Prefer composition over inheritance when combining functionality. Use inheritance when a genuine subtype relationship exists and the subtype can safely stand in for its parent

# How to choose ?

←PreviousThe Four Pillars of OOPNext→Database locking / atomic updates

On this page

AssociationAggregationCompositionComposition vs InheritanceHow to choose ?