Unified Modeling Language
UML (Unified Modeling Language) is an industry-standard modeling language used to describe the structure and behavior of software systems. It can be used to better understand objects and object-oriented programming, and to make it easier to conceptualize programming objects - the UML diagrams act like a template that can be used to write code from.
Unified Modeling Language (UML) is a standardized general-purpose modeling language in the field of object-oriented software engineering. The Unified Modeling Language includes a set of graphic notation techniques to create visual models of object-oriented software-intensive systems. (source)
A very simple version of UML can be used to model a class. A class diagram describes a template for creating multiple versions of something. Information about what is being created is stored as attributes. In programming languages these are often implemented as fields or properties. What the thing can do is described as operations (also called methods, behaviors, or functions in some programming languages).
Class Diagrams
A class diagram is a structural model. It models the idea or concept of an object. Not a specific object, but a class of objects. It is like a template for creating multiples of something; the template itself is different from one of the objects created from the template.

A basic class diagram is a rectangle with three sections.
- Top: name of the class
- Middle: attributes
- Bottom: operations
You can sketch out UML diagrams on paper, a whiteboard, or use an application (there are free options such as app.diagrams.net).
If you are using Visual Studio, depending on version and installed components, you can create UML diagrams that code can be generated from. You can also generate a UML diagram in Visual Studio from your existing code.
Class and Object Diagrams
Object diagrams represent instances. Each instance of a class can have unique information.
- Class Diagrams map out the abstract structure of classes (types, methods, and properties).
- Object Diagrams model concrete instances of classes at a specific point in time.
Class Diagram
Below is an example of a pet class. It defines the attributes all pets will have, and the operations they can perform.
| Class: Pet |
| Name: String Birthdate: DateTime |
| Eat(foodType) Sleep(timeLength) |
Object Diagrams
Instances of the pet class can be created that have all the attributes and operations, but may have unique values (such as the values stored as the name and birthdate).
| Instance: Spot |
| Name: Spot Birthdate: 12/15/2025 6:33:00 AM |
| Eat(foodType) Sleep(timeLength) |
| Instance: Snowball |
| Name: Snowball Birthdate: 05/08/2025 3:45:00 PM |
| Eat(foodType) Sleep(timeLength) |
Class and Object Relationships
There are several class and object relationships in object-oriented programming languages such as Java and C#.
| Relationship | Meaning |
| Association | Knows about or is related to |
| Aggregation | Has-a (weak ownership) |
| Composition | Owns-a (strong ownership) |
| Dependency | Uses |
| Inheritance | Is-a |
| Realization | Implements |
Association
A relationship between two objects or classes where one object references, knows about, or uses another. Association is different than containment in that association does not imply ownership. Aggregation and composition are commonly viewed as specialized forms of association.
- Association: a general semantic relationship; objects are related
Association Example
A game that allows a player to have several pets could have toys that all pets have access to. A pet can use a toy but they wouldn't own that toy; the toy would be available for all the pets to use.
In the example diagram below, the operation Play accepts an instance of a toy. The pet doesn't own the toy, but can use the toy. The instance of the toy might be one of many stored in a collection in another class (such as the example House below).
| Class: Pet |
| Name: String Birthdate: DateTime |
| Eat(foodType) Play(toy) Sleep(timeLength) |
| Class: Toy |
| Name: String Type: String |
| Class: House |
| Toys: Toy [] |
In contrast, if the pet contains a reference to a favorite toy, the class might look like the diagram below.
| Class: Pet |
| Name: String FavoriteToy: Toy Birthdate: DateTime |
| Eat(foodType) Play() Sleep(timeLength) |
Uses
One class "uses a" non-owned instance of another class. A player in a racing game uses a pit stop, but doesn't own it.
Aggregation and Composition (Containment)
Containment is a general concept describing how one object holds another. For example, an adventure game has a player, and a player has a collection of items in their inventory. These are both examples of one class containing an instance of another class.

There are variations of containment that are considered weaker (aggregation) and stronger (composition).
- Containment: a general concept that one object contains a reference to another object.
- Aggregation: considered a weaker "has a" relationship. The contained object can exist independently of the whole and may be shared or reassigned.
- Composition: considered a stronger "has a" relationship.
Containment Example
The Game class has an instance of the Person class (Player). Whether the type of containment is association, aggregation, or composition depends on the domain semantics. A player in a game often exists independently from the game object, however, suggesting aggregation or association.
| Class: Game |
| Name: String Player: Person |
| SetUp() SaveGame() |
The Person class has a collection of Item instances (Inventory).
| Class: Person |
| Name: String Inventory: Item[] |
| UseItem() |
| Class: Item |
| Name: String Description: String |
Has A
Containment is a "has a" relationship; A game "has a" Player.
Aggregation
This type of relationship is considered weaker as the contained object can exist independently of the whole. For example, imagine a game where a player can explore a world and collect items. The items will be stored in a collection in the player's instance, but each of the items can exist in the world without the player.
Composition
Composition is considered a stronger relationship because the contained object's lifecycle depends on the class that contains it. For example, consider a house that the player might own that has several rooms. Each room in the house will likely not exist without the house.
Dependency
If a class depends on another, it is considered a dependency. Examples are when an object is passed into a method, returned from a method, or used temporarily.
Dependency Example
A Save option in a game uses an instance of the FormatData class. The class depends on FormatData but doesn't store it. The dependency exists only while the method executes.
public void Save(FormatData playerData) {}
Dependency vs. Containment
Dependency means one class temporarily uses another. Containment means one object stores or contains another as part of its structure. A dependency can exist without any containment at all.
- Dependency: one class needs another class in order to do something.
- Containment: one object holds a reference to another object as part of its state.
Inheritance and Generalization
Generalization is the process of extracting shared characteristics from two or more classes, and moving them into a parent class (a base class). Child classes (derived classes) inherit the shared characteristics. Generalization is a process, for example when using UML to model the structure and behavior of a software system.
Inheritance is a mechanism in a programming language. It enables you to create a new class that reuses, extends, and modifies the behavior that is defined in another class. The parent class is called the base class, and the child class is called the derived class; a derived class reuses (inherits), extends, or modifies the behavior of a base class.
- Derived class: A class that inherits properties and methods from another class. Also called a child or a sub class.
- Base class: The class that a derived class inherits from is the base class. Also called a parent or super class.
The terms derived and base are common in languages such as C# and C++. Other languages like Java and Ruby use the terms superclass and subclass. They are often referred to as parent and child classes, also.
An example would be three pets: a bird, a cat, and a fish. All three pets might have the attributes 'name' and 'age', and all three might 'eat' and 'sleep'. These common characteristics can be placed in a base class called Pet. Unique attributes or operations are only in the derived classes. For example, all pets may eat, but only the bird can fly, the cat purr, and the fish swim.
Is A
A derived type "is a" base type. In the above diagram example, a Bird is a Pet. An instance of the Bird class is both a Bird and a Pet.
Single and Multiple Inheritance
Some languages allow only a single base or parent class. For example, C# only supports single class inheritance. C++, in contrast, has multiple inheritance; a child class can inherit properties and behaviors from more than one parent class.
Realization (Interface and Protocol)
Realization is a concept of implementation. Languages such as C# use interfaces, while Swift uses protocols. Modern Python also supports protocol-based typing through its type hint system.
Summary
- Dependency: Uses A
- Association: Knows about A
- Aggregation: Has A (weak ownership)
- Composition: Owns A (strong ownership)

