What is a Class Diagram?
The UML Class diagram is a graphical notation used to construct and visualize object oriented systems. A class diagram in the Unified Modeling Language (UML) is a type of static structure diagram that describes the structure of a system by showing the system’s:
- their attributes (or Properties),
- operations (or methods),
- and the relationships among objects.
What is a Class?
A Class is a blueprint for an object. Objects and classes go hand in hand. We can’t talk about one without talking about the other. And the entire point of Object-Oriented Design is not about objects, it’s about classes, because we use classes to create objects. So a class describes what an object will be, but it isn’t the object itself.
In fact, classes describe the type of objects, while objects are usable instances of classes. Each Object was built from the same set of blueprints and therefore contains the same components (properties and methods). The standard meaning is that an object is an instance of a class and object — Objects have states and behaviors.
A dog has states — color, name, breed as well as behaviors -wagging, barking, eating. An object is an instance of a class.
UML Class Notation
A class represent a concept which encapsulates state (attributes) and behavior (operations). Each attribute has a type. Each operation has a signature. The class name is the only mandatory information.
- The name of the class appears in the first partition.
- Attributes are shown in the second partition.
- The attribute type is shown after the colon.
- Attributes map onto member variables (data members) in code.
Class Operations (Methods):
- Operations are shown in the third partition. They are services the class provides.
- The return type of a method is shown after the colon at the end of the method signature.
- The return type of method parameters are shown after the colon following the parameter name. Operations map onto class methods in code
The +, — and # symbols before an attribute and operation name in a class denote the visibility of the attribute and operation.
- + denotes public attributes or operations
- - denotes private attributes or operations
- # denotes protected attributes or operations
Each parameter in an operation (method) may be denoted as in, out or inout which specifies its direction with respect to the caller. This directionality is shown before the parameter name.
Perspectives of Class Diagram
The choice of perspective depends on how far along you are in the development process. During the formulation of a domain model, for example, you would seldom move past the conceptual perspective. Analysis models will typically feature a mix of conceptual and specification perspectives. Design model development will typically start with heavy emphasis on the specification perspective, and evolve into the implementation perspective.
A diagram can be interpreted from various perspectives:
- Conceptual: represents the concepts in the domain
- Specification: focus is on the interfaces of Abstract Data Type (ADTs) in the software
- Implementation: describes how classes will implement their interfaces
The perspective affects the amount of detail to be supplied and the kinds of relationships worth presenting. As we mentioned above, the class name is the only mandatory information.
A class diagram is a central modeling technique that runs through nearly all object-oriented methods. This diagram describes the types of objects in the system and various kinds of static relationships which exist between them.
There are three principal kinds of relationships which are important:
- Association — represent relationships between instances of types (a person works for a company, a company has a number of offices.
- Inheritance — the most obvious addition to ER diagrams for use in OO. It has an immediate correspondence to inheritance in OO design.
- Aggregation — Aggregation, a form of object composition in object-oriented design.
Class Diagram Example: GUI
A class diagram may also have notes attached to classes or relationships.
Free UML Software Tool
In this article, I introduce two UML Tools:
- Visual Paradigm Community Editon (FREE) is a desktop UML tool with feature modeling capabilities. (possible update to commercial Editions)
- Visual Paradigm Online for general uml and other diagramming drawing.
30 Class Diagram Examples
- Free Class Diagram examples and templates editable in an online Class Diagram software: Visual Paradigm Online.
- Use the templates as a starting point to create your own Class Diagram.
- (Click to Instantly Edit the Class Diagram Examples)
For your convenience, the following examples are setup in Visual Paradigm Online. You can try it straight away without configuration or installation, have Fun!