Вы находитесь на странице: 1из 24

UML Class Diagrams

Presented By P.Vinitha M.Sc., M.Phil., (M.B.A)

UML Class Diagrams


The class diagram is core to object-oriented design. Class Diagrams illustrate classes, interfaces, and their associations. They are used for static object modeling. Class diagrams describe three different perspectives when designing a system, conceptual, specification, and implementation.

UML Class Diagrams


The purpose of the class diagrams :
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.

Essential Elements of a UML Class Diagram


Class Attributes Operations Relationships
Associations Generalization Dependency Realization

Constraint Rules and Notes

UML Class Diagrams

Definition: Classifier
A UML classifier is "a model element that describes behavioral and structure features . Classifiers can also be specialized. They are a generalization of many of the elements of the UML, including classes, interfaces, use cases, and actors. In class diagrams, the two most common classifiers are regular classes and interfaces.

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

UML Class Diagram Notations


Attributes
An attribute is a property of a class. In the example above, we are told that a Contact has an address, a city, a province, a country and a postal code. Methods to set and retrieve attribute data are often called Accessor methods The format for attributes is:

visibility name: type = defaultValue


The visibility is as follows:

- Private + Public

# Protected

~ Package

UML Class Diagram Notations


Operations
The operations listed in a class represent the functions or tasks that can be performed on the data in the class. The format for operations is: visibility name (parameters): type Parameters take the format: direction name: type = default value The direction can be one of in, out, inout or it can be unspecified.

UML Class Diagram Notations


Generalization
The generalization link is used between two classes to show that a class incorporates all of the attributes and operations of another, but adds to them in some way.
It is shown with a solid line and fat triangular arrow from the subclass to superclass

UML Class Diagram Notations


Interfaces
Many object oriented programming languages do not allow for multiple inheritance. The interface is used to solve the limitations posed by this.

UML Class Diagram Notations


Dependencies
A dependency exists between two elements if changes to one will affect the other. Dependency is illustrated with a dashed arrow line . To show the type of dependency, or to help a tool with code generation, the dependency line can be labeled with keywords

UML Class Diagram Notations


Associations
A semantic relationship between two or more classes that specifies connections among their instances. Example: An Employee works for a Company
Employee Department Company

Role 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.

UML Class Diagram Notations


Association
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
Exactly one Zero or more (unlimited) One or more Zero or one (optional association) Specified range Multiple, disjoint ranges 1 * (0..*) 1..* 0..1 2..4 2, 4..6, 8

UML Class Diagram Notations


Role name
instructor Association name

StaffMember

1..*

instructs
Navigable (uni-directional) association

Student
Role * pre requisites 0..3

Multiplicity

Courses
Reflexive association

UML Class Diagram Notations


Qualified Association
A qualified association has a qualifier that is used to select an object (or objects) from a larger set of related objects, based upon the qualifier key. For example, if a ProductCatalog contains many ProductDescriptions, and each one can be selected by an itemID, then the UML notation is shown below

UML Class Diagram Notations


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

Car

2..*

Door Part

1..*

House

Whole

UML Class Diagram Notations


Composition, also known as composite aggregation, is a strong kind of whole-part aggregation
A composition relationship implies that An instance of the part (such as a square) belongs to only one composite instance (such as one board) at a time The part must always belong to a composite The composite is responsible for the creation and deletion of its parts either by itself creating/deleting the parts, or by collaborating with other objects.

UML Class Diagram Notations


Keywords
A UML keyword is a textual decoration to categorize a model element. For example, the keyword to categorize that a classifier box is an interface is interface Most keywords are shown in guillemet ( ) but some are shown in curly braces, such as {abstract}, which is a constraint
Keyword actor Meaning classifier is an actor Example Usage in class diagram, above classifier name

interface
{abstract} {ordered}

classifier is an interface
abstract element; can't be instantiated a set of objects have some imposed order

in class diagram, above classifier name


in class diagrams, after classifier name or operation name in class diagrams, at an association end

UML Class Diagram Notations


UML Properties and Property Strings
In the UML, a property is "a named value denoting a characteristic of an element. Some properties are predefined in the UML, such as visibility a property of an operation. Others can be userdefined. Properties of elements may be presented in many ways, but a textual approach is to use the UML property string {name1=value1, name2=value2} format, such as {abstract, visibility=public}.

UML Class Diagram Notations


Constraints
A UML constraint is a restriction or condition on a UML element. It is visualized in text between braces; for example: { size >= 0 }. The text may be natural language or anything else, such as UML's formal specification language, the Object Constraint Language

Note Symbols: Notes, Comments, Constraints, and Method Bodies


A UML note symbol is displayed as a dog-eared rectangle with a dashed line to the annotated element. A note symbol may represent several things, such as: A UML note or comment, which by definition have no semantic impact A UML constraint, in which case it must be encased in braces '{}' A method body the implementation of a UML operation

UML class diagram showing a method

What's the Relationship Between Interaction and Class Diagrams


From interaction diagrams the definitions of class diagrams can be generated.

Вам также может понравиться