Class Diagram Theory

Class diagram is a type structure diagram. The purpose of structure diagrams is to show the static structure of the system being modeled. They include the class, component, and/or object diagrams. Class diagrams are used to describe the types of objects in a system, classes and interfaces, and the relationships among them. Class diagram model class structure and contents using design elements such as classes, packages and objects. When designing a system, it describe three perspectives - conceptual, specification and implementation. It is the main building block in object oriented modeling.
A class diagram is a pictorial representation of the detailed system design. Class diagrams are useful in all forms of object-oriented programming (OOP). In a class diagram, the classes are arranged in groups that share common characteristics. A class diagram resembles a flowchart in which classes are portrayed as boxes.
The class diagrams are the only diagrams which can be directly mapped with object oriented languages and thus widely used at the time of construction. It represents the static view of an application. Class diagram is not only used for visualizing, describing and documenting different aspects of a system but also for constructing executable code of the software application. The class diagram describes the attributes and operations of a class and also the constraints imposed on the system.
The purpose of the class diagram can:
  • Analysis and design of the static view of an application.
  • Describe responsibilities of a system.
  • Base for component and deployment diagrams.
  • Forward and reverse engineering.
  • Describing the functionalities performed by the system.
  • Construction of software applications using object oriented languages.
Basic elements of Class diagram
Class:
A class is a representation of an object. Classes form the main building blocks of an object-oriented application. the representation of a class is a rectangle containing three compartments stacked vertically, as shown below:

The top compartment shows the class's name. The middle compartment lists the class's attributes. The bottom compartment lists the class's operations. When drawing a class element on a class diagram, you must use the top compartment, and the bottom two compartments are optional.
Package
Packages enable modelers to organize the model's classifiers into namespaces, which is sort of like folders in a filing system. Dividing a system into multiple packages makes the system easier to understand, especially if each package represents a specific part of the system. Packages are great for organizing your model's classes. It is represented by a large rectangle which contains the classes inside it.

Interface
There are classes that have nothing but pure virtual functions, they are a special element called an interface. The difference between a class and an interface is that a class can have an actual instance of its type, whereas an interface must have at least one class to implement it. An interface is drawn just like a class, but the top compartment of the rectangle also has the text "«interface»".

Associations
It is represented by thin line connecting two classes, which is sometime labeled. The label is optional, is one or two words describing the association. In the following figure, one interface is associated with two classes in a package.

Some guideline to drawing class diagram are as follows:

  • The name of the class diagram should be meaningful to describe the aspect of the system.
  • Each element and their relationships should be identified in advance.
  • Responsibility (attributes and methods) of each class should be clearly identified.
  • For each class minimum number of properties should be specified. Because unnecessary properties will make the diagram complicated.
  • Use notes when ever required to describe some aspect of the diagram. Because at the end of the drawing it should be understandable to the developer/coder.

Post a Comment

Previous Post Next Post