DEV Community

Cover image for Class Diagrams Relationships

Class Diagrams Relationships

consolata gicheru
Living in the moment 😎flutter App developer , Power Platform , Microsoft Learn student ambassador, #just smile😊
・1 min read

Class diagrams are the main building block in object-oriented modeling. They are used to show the different objects in a system, their attributes, their operations and the relationships among them.

Classes are interrelated to each other in specific ways. In particular, relationships in class diagrams include different types of logical connections. The following are such types of logical connections that are possible in Unified Modelling Language:

  • Association
  • Composition
  • Aggregation
  • Inheritance
  • Generalization
  • Specialization

An example to understand the relationships
consider a person with his/her gadgets (phones, Laptops etc )

From here we have 2 classes class person and class gadget
when a person charges a gadget that creates an Association between the two classes

Composition implies a relationship where the child cannot exist independent of the parent.
Battery is part of a phone
A phone can't exist without a battery hence that is an example of composition

A battery and a phone can however exist independently . This is an example of Aggregation
Aggregation implies a relationship where the child can exist independently of the parent

Generalization is a mechanism for combining similar classes of objects into a single, more general class.
Phones and Laptops are examples of Gadgets .
class phones can be a subclass of class Gadgets
This is an example of Generalization as phones inherit attributes from the super class Gadgets

Specialization is the reverse process of Generalization means creating new sub-classes from an existing class hence in the example we could have class phones being created from class Gadgets

Representation of the relationships

Alt Text

Discussion (2)

femolacaster profile image
femolacaster • Edited

Yeah. The concept could also be thought this way - by relating them to nouns.

Class/Object -Noun. E.g. person, gadgets.

Association-Verbs. E.g charges which is the link between person and gadget. Person charges gadgets.

Composition-Possessive adjective. E.g. My phone. The only reason your phone is in existence is because you which is a noun exist.

Aggregation-Descriptive adjective. E.g. Beautiful phone or Ugly phone. The extra description doesn't make it less of a phone or doesn't make the phone seize to exist. It's still a phone.

Generalization-Common nouns. E.g. Laptops, phones are all gadgets.

Specialization- Proper noun. E.g. Femi. Consolata. Abisola. HP laptop 5216.

consolatacleah profile image
consolata gicheru Author

This is really awesome @femolacaster 🥳🥳