Top Banner
Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to http://www.paxcel.net Class and Object diagrams in UML (Unified Modeling Language) By:- Tanjot Singh Sandhu
24

Introduction to UML

May 24, 2015

Download

Technology

Class and Object diagrams in UML
(Unified Modeling Language)
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

http://www.paxcel.net

Class and Object diagrams in UML(Unified Modeling Language)

By:-Tanjot Singh Sandhu

Page 2: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

UML Background

UML is a standard language for designing and documenting a system in an object-oriented manner.

UML includes a set of graphic notation techniques to create visual models of object-oriented software-intensive systems.

The standard is managed, and was created, by the Object Management Group (OMG).

UML versions - UML 1.0, 1.1 1.2, 1.3, 1.4, and 1.5 UML 2.0 – adopted by OMG in 2005. UML 2.3 - formally released in May 2010. UML 2.4.1 - formally released in August 2011.

Page 3: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Technical aspects of UML

Building block of UML Things

Structural Things (Class, Interface, Collaboration, Use case, Active class, Component, Node)

Behavioral things (Message , State) Grouping things (Package) Annotational things (Notes)

– Relationships• Dependency (represented as a dashed directed line)• Association (rendered as solid line)• Generalization (represented as a solid line with a hollow

arrowhead pointing to the parent)• Realization (represented as a dashed line with a hollow

arrowhead pointing to the parent)

Page 4: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Technical aspects of UML (Continued)

Diagrams• Structural/ Static

– Class Diagram– Object Diagram– Component Diagram– Deployment Diagram

• Behavioral/ Dynamic– Use case Diagram– Sequence Diagram– Collaboration Diagram– Statechart Diagram– Activity Diagram

Page 5: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Class Diagram

Class diagram represents a set of classes, interfaces and their relationships.

It can be used to model Collaboration of classes, Database schema. 

Page 6: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Class Visibility

Visibility applies to attributes or operations, and specifies the extent to which other classes can use a given class’s attributes or operations.

Three levels of visibility are possible:

1. Public level - usability extends to other classes +

2. Protected level - usability is open only to classes that

inherit from original class #

3. Private level - only the original 

Page 7: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Association in Class diagrams

By grouping and relating between the classes we create module and these are termed as Association.

In order to associate them we need to draw solid arrowed lines between the classes as shown in the below figure.

Example – A Person works for a Company.

Page 8: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Association Properties

Name

Name of the association Role

The specific role of the association Multiplicity

Indicates the number of objects that are connected Type

Plain association, aggregation, composition Direction

Direction can also be shown for a association

Page 9: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Association Multiplicity

One class can be linked to instances of many other classes.

That is, it indicates how many objects of one class relate to one object of another class. It is indicated by a single number or a range of numbers.

Thus, multiplicity can be termed as classes having multiple associations.

Page 10: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Multiplicity Example

A teacher teaches 1 to 3 courses (subjects). Each course is taught by only one teacher. A student can take between 1 to 5 courses. A course can have 10 to 300 students.

Page 11: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Aggregation Relationships

Aggregation is a whole/part relationship. In below example, Window is the whole, and Shape is part of Window.

Aggregation is represented with a hollow/ open diamond. Ends of a relationship are referred to as its “roles”. Notice

that the role at the Shape end of the aggregation is marked with a “*”. This indicates that the Window contains many Shape instances.

Page 12: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Aggregation Relationships

Aggregation is a whole/part relationship. In below example, Window is the whole, and Shape is part of Window.

Aggregation is represented with a hollow/ open diamond. Ends of a relationship are referred to as its “roles”. Notice

that the role at the Shape end of the aggregation is marked with a “*”. This indicates that the Window contains many Shape instances.

Page 13: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Aggregation vs Composition

Both refer to member object but the existence of member object (without the containing class or object or after the lifetime of the containing class or object) makes the difference.

Aggregation is also known as a 'has a' relationship because the containing object has a member object and the member object can survive or exist without the enclosing or containing class or can have a meaning after the lifetime of the enclosing object also.

Example ('has a'): Room has a table and the table can exist without the room. The table can have meaning without the room also.

Page 14: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Aggregation vs Composition (Continued)

Composition is also known as a 'is a part of' relationship because the member object is a part of the containing class.

Member object cannot survive or exist outside the enclosing or containing class or does not have a meaning after the lifetime of the enclosing object.

Example ('is a part of'): IMEI no. is a part of the Mobile. IMEI no. cannot exist without the mobile and the IMEI no. has no meaning after the lifetime of the mobile.

Page 15: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Example - Aggregation vs Composition

Aggregation

As you can see, Person does not manage the lifetime of Address. If Person is destroyed, the Address still exists.

Page 16: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Example - Aggregation vs Composition

Composition

If we were going to model a car, it would make sense to say that an engine is part-of a car.

Within composition, the lifetime of the part (Engine) is managed by the whole (Car), in other words, when Car is destroyed, Engine is destroyed along with it.

As you can see in the example code above, Car manages the lifetime of Engine.

Page 17: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Inheritance Relationships

Depicted by a hollow triangular arrowhead. One or more lines proceed from the base of the arrowhead

connecting it to the derived classes.

Page 18: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Dependency Relationships

Sometimes the relationship between two classes is very weak. They are not implemented with member variables at all. Rather they might be implemented as member function arguments.

Consider, for example, the Draw function of the Shape class. Suppose that this function takes an argument of type DrawingContext.

Represented as dashed-arrow line.

Page 19: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

An abstract class and interface in UML

Stereotype – Type/ word or string within two surrounding characters “«»”, called guillemets (pronounced Gee-may).

Interface is represented by stereotype, «type» in the class diagram.

Abstract classes are represented by ‘{abstract}’ as shown in figure.

Page 20: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Some of the commonly used stereo types while writing UML:

<<Application>>:- Used to represent a UI system in a application.

<<Database>> :- represents a database in a application.

<<Table>> :- A table with in database.

<<Library>> :- A reusable library or function.

<<File>> :- Physical file on a folder.

<<Executable>> :- A software component which can be executed.

<<Web services>> :- Represents a web service.

<<JDBC>> :- Java database connectivity , a JAVA API to connect to database.

<<ODBC>> :- Open database connectivity , a Microsoft API to connect to database.

Page 21: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Object Diagram

Class diagrams shows the types and how they are linked.

Object diagram gives a pictorial representation of class diagram at any point of time.

We represent object with Object Name: Class Name. Property is represented by ‘PropertyName=Value’. We can show multiplicity as different objects of same class. Other UML entities, such as an aggregation or composition

symbol (a diamond) may also appear on an object diagram. Note: - Object diagrams should only be drawn to represent

complicated relationship between objects. It’s possible that it can also complicate your technical document as lot. So use it sparingly.

Page 22: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Object Diagram (Continued)

Draw an object diagram to illustrate a real-life example of a class and its relationships.

Object diagrams can help clarify classes and inheritance and are sometimes drawn while planning classes.

Helpful in understanding the system from practical perspective.

Assist non-programming stakeholders who may find class diagrams too abstract.

An object can also be thought of as the description of an individual within a group.

Hence “CheckingAccount” might be defined as a UML class and “John’s checking account at Agency Bank” would be illustrated as an object diagram (on next slide).

Page 23: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

Object Diagram... continued

Object diagrams use notation very similar to class diagrams.

Page 24: Introduction to UML

Paxcel technologies. www.paxcel.net This is the exclusive property of Paxcel Technologies. This may not be reproduced or given to third parties without their consent.

References

http://en.wikipedia.org/wiki/Unified_Modeling_Language http://www.dotnetfunda.com/articles/article143.aspx http://www.dotnetfunda.com/articles/article145.aspx http://www.careerride.com/UML-FAQs.aspx http://www.objectmentor.com/resources/articles/umlClassDiagrams.pdf http://www.altova.com/umodel/object-diagrams.html http://design-antony.blogspot.in/2007/07/aggregation-vs-composition.html http://www.c-sharpcorner.com/UploadFile/pcurnow/compagg07272007062838AM/

compagg.aspx