Lesson 13: UML and C++
13.1 An Overview of UML
What is UML?
UML, Unified Modeling Language, is a standard notation for modeling real-world objects as a first step in developing an object-oriented program. It describes one consistent language for specifying, visualizing, constructing, and documenting the artifacts of software systems. UML is not a programming language, and it can be described as the successor of object-oriented (OO) analysis and design.
Object-Oriented Concepts
An object contains both data and methods that control the data. The data represents the state of the object. A class describes an object, and they also form a hierarchy to model the real-world system. The hierarchy is represented as inheritance, and the classes can also be associated in different ways as per the requirement.
Objects are the real-world entities around us, and basic concepts such as abstraction, encapsulation, inheritance, and polymorphism can all be represented using UML.
UML is powerful enough to represent all the concepts that exist in object-oriented analysis and design. UML diagrams are representations of object-oriented concepts only. Thus, before learning UML, it becomes important to understand the OO concept in detail.
Following are some fundamental concepts of the object-oriented world −
- Objects − Objects represent an entity and the basic building block.
- Class − Class is the blueprint of an object.
- Abstraction − Abstraction represents the behavior of a real-world entity.
- Encapsulation − Encapsulation is the mechanism of binding the data together and hiding them from the outside world.
- Inheritance − Inheritance is the mechanism of making new classes from existing ones.
- Polymorphism − It defines the mechanism to exist in different forms.
OO Analysis and Design
OO can be defined as an investigation, and to be more specific, it is the investigation of objects. Design means the collaboration of identified objects.
Thus, it is important to understand the OO analysis and design concepts. The most important purpose of OO analysis is to identify objects of a system to be designed. This analysis is also done for an existing system. Now an efficient analysis is only possible when we are able to start thinking in a way where objects can be identified. After identifying the objects, their relationships are identified, and finally, the design is produced.
The purpose of OO analysis and design can be described as −
- Identifying the objects of a system.
- Identifying their relationships.
- Making a design which can be converted to executables using OO languages.
There are three basic steps where the OO concepts are applied and implemented. The steps can be defined as
OO Analysis ➤ OO Design ➤ OO implementation using OO languages
The above three points can be described in detail as −
- During OO analysis, the most important purpose is to identify objects and describe them in a proper way. If these objects are identified efficiently, then the next job of design is easy. The objects should be identified with responsibilities. Responsibilities are the functions performed by the object. Each and every object has some type of responsibility to be performed. When these responsibilities have collaborated, the purpose of the system is fulfilled.
- The second phase is OO design. During this phase, emphasis is placed on the requirements and their fulfillment. In this stage, the objects are collaborated according to their intended association. After the association is complete, the design is also complete.
- The third phase is OO implementation. In this phase, the design is implemented using OO languages such as Java, C++, etc.
Role of UML in OO Design
UML is a modeling language used to model software and non-software systems. Although UML is used for non-software systems, the emphasis is on modeling OO software applications. Most of the UML diagrams discussed so far are used to model different aspects such as static, dynamic, etc. Now, whatever the aspect, the artifacts are nothing but objects.
If we look into the class diagrams, object diagrams, collaboration diagrams, interaction diagrams, all would basically be designed based on the objects.
Hence, the relationship between OO design and UML is very important to understand. The OO design is transformed into UML diagrams according to the requirement. Before understanding the UML in detail, the OO concept should be learned properly. Once the OO analysis and design are done, the next step is very easy. The input from OO analysis and design is the input to UML diagrams.
13.2 UML Blocks
s UML describes the real-time systems; it is very important to make a conceptual model and then proceed gradually. The conceptual model of UML can be mastered by learning the following three major elements −
- UML building blocks
- Rules to connect the building blocks
- Common mechanisms of UML
This session describes all the UML building blocks. The building blocks of UML can be defined as −
- Things
- Relationships
- Diagrams
Things
These are the most important building blocks of UML. Things can be −
- Structural Things
- Behavioral Things
- Grouping Things
- Annotation Things
Structural Things
Structural things define the static part of the model. They represent the physical and conceptual elements. Following are the brief descriptions of the structural things.
Class − Class represents a set of objects having similar responsibilities.
Behavioral Things
Grouping Things
Annotation Things
Relationships
The relationship is another important building block of UML. It shows how the elements are associated with each other, and this association describes the functionality of an application.
Aggregation
Associations
Objects are often associated with or related to other objects. When you model associations in UML class diagrams, you show them as a thin line connecting two classes, as shown in Figure __. Associations can become quite complex; consequently, you can depict some things about them on your diagrams. Although highly recommended, the optional label is typically one or two words describing the association. For example, professors instruct seminars.
Indicator | Meaning |
---|---|
0..1 | Zero or one |
1 | One only |
0..* | Zero or more |
1..* | One or more |
n | Only n (where n > 1) |
0..n | Zero to n (where n>1) |
1..n | One to n (where n>1) |
Composition
Containment
Dependency
Dependency is a relationship between two things in which change in one element also affects the other. A dependency is generally shown as a dashed arrow pointing from the client (dependent) at the tail to the supplier (provider) at the arrowhead. The arrow may be labeled with an optional stereotype and an optional name. Because the direction of the arrow goes opposite to what we would normally expect, I usually stereotype it as a client «depends on» supplier.
Exception
Generalization
Generalization can be defined as a relationship that connects a specialized element with a generalized element. It basically describes the inheritance relationship in the world of objects.
Implementation
Realization
Realization can be defined as a relationship in which two elements are connected. One element describes some responsibility, which is not implemented and the other one implements them. This relationship exists in the case of interfaces.
Relationship
Unidirectional Association
Diagrams
UML diagrams are the ultimate output of the entire discussion. All the elements' relationships are used to make a complete UML diagram, and the diagram represents a system.
The visual effect of the UML diagram is the most important part of the entire process. All the other elements are used to make it complete.
UML includes the following nine diagrams, the details of which are described in the subsequent chapters.
- Class diagram
- Object diagram
- Use case diagram
- Sequence diagram
- Collaboration diagram
- Activity diagram
- Statechart diagram
- Deployment diagram
- Component diagram
13.3
13.4
13.5
13.6