Unified Modeling Language(UML) - Class Diagrams.

First 2-3 years in start-up, we are always in hurry to code new features based on hallway, coffee break discussions. No documents, no design and no formal code comments also. After some point of time, our products are out there in market and everybody liked it. Now comes the documentation trouble, we have to document all, whatever we designed and developed in past, primarily in our mind. If you are designer, you no need to write 100-200 pages document describing what you did. All we need are excellent diagrams, sketches and flow from start to end. UML is the only way to achieve this.

UML is not a strict language, in other words, there is no compiler out there to check our code against standards. A rough sketch can do the purpose. UML is useful on both forward and reverse engineering. The main component of UML is class diagrams, there is almost none design document without class diagrams. In class diagrams, the following notations and relationships are really important. This class diagrams are going to be a blue print for long time, hence this notations are important to communicate because we don't know whether designer who developed this diagram going to be with company or not.

1. Associations
In Class diagrams, if a class associate with other class, the a solid line with a arrow, from source to target. A perfect example would be, Customer and Order class. Order class must give a customer id, who created order. Since we can identify an unique customer id from order, Order class has an association with Customer class, that same with customer class also, from customer class we can find orders by the customers.

2. Compositions
A class can have other class's reference in it. This is useful when we want to utilize other class's methods without inheritance. Decorator pattern is mainly based on compositions.

3. Generalization
This is for grouping similar classes, to add these similar methods in a super class and all other classes are derived(inheritance) from it. This is nothing but super class and sub class notation in UML.

4. Aggregation
Aggregation and association are interchangeable. There is no major difference between them. A car has an engine, then car (whole) has a aggregation relationship with engine (part). To make our life simple, we can use association notation instead of aggregation. Most of the UML gurus discourage us to use aggregation notation in class diagram. We can just use association for top level design and composition and aggregation can be used in detailed design.

5. Realization
Realization is relationship between an interface and implements class. The interface specifies behaviours and a class implements that behaviour then the class realize relationship with interface.

6. Dependency
Dependency relationship as name implies, if one class change, other class's state changes then these two classes are dependency relationship. MVC pattern can be good example of dependency relationship.

The other important elements from class diagrams are multiplicity (upper bound..lower bound), Stereotype, visibilities and properties.

Comments

Popular posts from this blog

Coupon Crazy

Google's Killer Application.

Uncontrolled Musing