Sunday 30 September 2012

Introduction to Class Diagram with Examples


                                                   The UML Class Diagrams

       A class diagram describes the types of objects in the system and the various kinds of static relationships that exist among them. It is a graphical representation of a static view on declarative static elements and a central modeling technique that runs through nearly all object-oriented methods. The richest notation in UML.
We Discuss here :-

Essential Elements:

1. Classes

2. Attributes

3. Operations

4. Relationships
              –Associations
              –Generalization
              –Dependency
              –Realization

5. Examples of Class Diagram for 
          - Library management system
          - Hospital System





1. Classes :





A class is the description of a set of objects having similar attributes, operations, relationships and behavior.


2. Attributes :

Classes have attributes that describe the characteristics of their objects.

Attributes are atomic entities with no responsibilities.

Attribute syntax (partial):
–[visibility] name [ : type ] [ = defaultValue ]
Class scope attributes are underlined.




3. Operations :

Operations are the processes that objects of a class (or the class itself) know to carry out.

Operations correspond to method declarations rather than method definitions.

Operation syntax (partial):
–[ visibility ] name ( [ parameter-list ] ) [ : return-type ]
–where parameter-list is a comma separated list of formal parameters, each specified using the syntax: name : type [ = defaultValue ]

Example:
max(a : int, b : int) : int


4. Visibility:

 Visibility describes whether an attribute or operation is visible and can be referenced from classes other than the one in which they are defined.
 Language dependent
 UML provides four visibility abbreviations:
+ (public) – (private) # (protected) ~ (package)


5 Relationships : Associations:


A semantic relationship between two or more classes that specifies connections among their instances.

A structural relationship, specifying that objects of one class are connected to objects of a second (possibly the same) class.

Example: “An Employee works for a Company”
An association between two classes indicates that objects at one end of an association “recognize” objects at the other end and may send messages to them.
–This property will help us discover less trivial associations using interaction diagrams.
To clarify its meaning, an association may be named.
–The name is represented as a label placed midway along the association line.
A role is an end of an association where it connects to a class.
–May be named to indicate the role played by the class attached to the end of the association path.


Multiplicity :


The number of instances of the class, next to which the multiplicity expression appears, that are referenced by a single instance of the class that is at the other end of the association path.

Indicates whether or not an association is mandatory.

Provides a lower and upper bound on the number of instances.


Relationship : Aggregation:


A special form of association that models a whole-part relationship between an aggregate (the whole) and its parts.

Example :

A Door is “part of” a Car

–Are some operations on the whole automatically applied to its parts?

Move the car, move the door.

–Are some attribute values propagated from the whole to all or some of its parts?

The car is blue, therefore the door is blue.

–Is there an intrinsic asymmetry to the relationship where one class is subordinate to the other?

A door is part of a car. A car is not part of a door.



Relationship : Generalization:

Indicates that objects of the specialized class (subclass) are substitutable for objects of the generalized class (super-class).–“is kind of” relationship.

A sub-class inherits from its super-class

–Attributes

–Operations

–Relationships

A sub-class may

–Add attributes and operations

–Add relationships

–Refine (override) inherited operations



Relationship : Dependency:

A dependency is a relation between two classes in which a change in one may force changes in the other although there is no explicit association between them.

A stereotype may be used to denote the type of the dependency.

Examples:

–A class calls a class scope operation of another class.

–A class is a friend of another class.

–A class depends on the interface of another class.

–A class contains an operation that takes an object of another class as a parameter.

–A class accesses a global object of another class.


Class Diagram Examples:

Library Management System


Hospital System







No comments:

Post a Comment