Class Diagram Basics

Basic Guide to Understanding Class Diagrams

Of all the UML diagram types, class diagrams are one of the most used diagram types. This is understandable because they are the building blocks of object oriented programming languages. They are some of the first diagram types thought in computer engineering and software engineering courses and compared to most other they are easier to understand as well. Although easy to understand they are a powerful tool capable of modeling real life systems. One area most people struggle with is understand relationships in class diagrams and I will cover them briefly here as well.

A basic class diagram with attributes and operations
A basic class diagram with attributes and operations

Class Diagram

The basic building block of class diagrams. Typically a class diagram will represent an entity in the real world. The image next to this text is a good example of how simple class diagram. Here the entity is "loan account". Properties of the entities are listed down as attributes. In this case they are type, accountName, dateReleased and loanAmount. The actions performed by the entity are called operations. In this example they are renew and extend. It is important to note that this is only an example, typically an loan amount will have many more attributed and operations.

Relationships in Class Diagrams

This is one area where many people struggle to understand. This is more to do with the similarity of the symbols and poor understanding of the symbols. There are 8 relationship types in UML class diagrams.

  • Association
  • Directed Association
  • Reflexive Association
  • Multiplicity
  • Aggregation
  • Composition
  • Inheritance
  • Realization

Although there are eight as you can see from the below image they differ only by a simple arrow head, a simple set of numbers beside the line etc. Forget to add the numbers beside Multiplicity relationship and you get an association, giving a different meaning to the diagram. So it is no wonder people struggle with relationships in class diagrams.

Various Relationships in Class Diagrams
Various Relationships in Class Diagrams

Drawing a Class Diagrams

The final step is to come up with the class diagram, which is basically a set of classes connected by various relationship types. Some times two people can come up with different class diagrams for the same problem but there shouldn't be drastic differences. Normally most people will agree upon the class, differences come when agreeing upon various relationships.

More by this Author


Comments

No comments yet.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working