Introduction
Unified Modeling Language is a graphical language used to describe objects in a system. This post describes the UML class diagrams and relationships among business entities in the system.
Domain Model represents the relation ship between logical entities in the system. It also illustrates how different entities in application domain would interact with each other.
Class
Relationships
Class Diagrams
Class diagram represents how different entities are related to each other in an object-oriented system. We are using OrderManagementSystem to demonstrate the class diagram.
The rectangular boxes denote the classes with name and fields. The arrows define relationships between entities.
The following are the relationships among classes
- Dependency Relationship
- Association
- Generalization
- Realization
Dependency Relationship
This relationship exists between two elements if changes to one element will affect the other. It is a simple relation ship where entity 1 depends on entity 2 in such a way that any change in entity2 might break entity1. This is one way relationship where change in entity 1 will not affect entity2 in any manner..
public class Entity1 { public void MethodX (Entity2 en) { // . . . } }
Association Relationship
Association shows the relationship between instances of classes. It is similar to a dependency except that it specifies the relationship in stricter form. Instead of using Entity2 as a local variable in Association it would be a global variable. Graphically it represents with a strong arrow between the entities.
public class Order //entity1 { private Customer _customer; public Customer GetCustomer () { return _customer; } }
In the above code, customer is part of order class. Customer object forms a part of the state of the order. If you have an order object, you can easily identify the customer associated with it. Hence association is a stronger form of dependency.
Aggregation
Aggregation is a part-of relationship between classifiers. The life time of one object is not necessarily controlled by another object. An Aggregation is represented by a straight arrow, with an empty diamond at the tail.
In above example, Entity2 is part of Entity1. If you destroy the parent class(Entity1) in an aggregation relationship, the child class can survive on its own.
OrderLine can have multiple quantities of one product. If OrderLine is destroyed, it does not mean that we delete the product as well. If an order is cancelled then all of its products will not be destroyed. The products will only be disassociated from particular order.
Composition
Composition is whole-part relationship where life time of part is controlled by the whole.
In above diagram Entity2 is controlled by Entity-1. If Entity 1 is destroyed in a composition (strong) relationship, Entity 2 destroyed as well.
Customer can place multiple orders; order can have one or more products. An Order object can not exist on its own with out customer object. If customer goes out of scope then order also goes out of scope too.
Generalization
In UML inheritance is depicted as generalization relationship. A generalization relationship is also known as “is-a†relationship where specialized class is based on a general class
Realization
A Realization relationship exists between the two classes where one class implements the behavior specified by other class.
Example: A realization relationship connects an interface to an implementing class.
Conclusion
This post explained the how to data model an application using UML and also explained the relationship among the entities in the UML.
Excellent!
Simple and precise!
Very well explained,