Skip to main content

UML Class Relationships and Hierarchies in Object-Oriented Programming

Explore the fundamental concepts of Object-Oriented Programming (OOP) using UML class diagrams. This guide details classes, objects, encapsulation, visibility, association, multiplicity, generalization hierarchies, aggregation, composition, and interfaces.

Save this reading to your study set

Sign up free

In software modeling, specifically within the Object-Oriented (OO) paradigm, we aim to represent real-world entities as autonomous structures. These structures, known as objects, possess their own identity, state, and behavior. To organize these objects into a coherent system, we use Unified Modeling Language (UML) to define how they relate to one another through various types of connections and hierarchies.

The Building Blocks: Classes and Objects

Before understanding relationships, we must distinguish between a class and an object. A class is a construction plan or blueprint for a set of similar objects. It defines the shared structure (attributes) and shared behavior (operations/methods) that all its instances will possess.

An object is a specific instance of a class. While all objects of a class share the same structure, each object has a unique Object Identity (OID) assigned by the system at the moment of creation. This identity ensures that even if two objects have identical attribute values, they remain distinct entities.

Encapsulation and Visibility

To protect the integrity of an object's state, OO design uses encapsulation. This is the ability to hide an object's internal details (attributes and methods) from the outside world. Access is controlled via visibility modifiers:

  • Private (-): Accessible only within the class.
  • Protected (#): Accessible within the class and its subclasses.
  • Public (+): Accessible from anywhere.

Connections: Association and Multiplicity

When two or more classes interact or exchange messages, they are said to have a connection (also known as an association).

Cardinality and Multiplicity

Connections are characterized by multiplicity (or cardinality), which defines the minimum and maximum number of occurrences of one class that can be associated with a single instance of the related class.

Keep reading for free.

Create an account to finish this reading and make it part of your study routine.

Continue reading free

Already have an account? Log in

Updated

Study it your way.

Import this reading into your study set to get started with another study mode.

Make it your own.

Keep this reading in a new study set, or add it to one you already use.