UML (Unified Modeling language)

18
UML (UNIFIED MODELING LANGUAGE) Prepared by Miss Simab Shahid ([email protected]) Lecturer computer Science and Software Engineering department, University of Hail

description

UML (Unified Modeling language). Prepared by Miss Simab Shahid ([email protected]) Lecturer computer Science and Software Engineering department, University of Hail. Introduction to UML and Patterns. Software design is a process of problem solving and planning for software solution. - PowerPoint PPT Presentation

Transcript of UML (Unified Modeling language)

Page 1: UML (Unified Modeling language)

UML(UNIFIED MODELING LANGUAGE)

Prepared by

Miss Simab Shahid ([email protected])

Lecturer computer Science and Software Engineering department, University of Hail

Page 2: UML (Unified Modeling language)

INTRODUCTION TO UML AND PATTERNS

Software design is a process of problem solving and planning for software solution.

There are different designing tools are available for software designing.

UML and patterns are two software design tools that can be used within the context of any OOP (Object-Oriented programming) language.

UML (Unified Modeling Language) is a graphical language used for designing and documenting OOP software.

A pattern in programming is a kind of template or outline of a software task.

2

Sim

ab S

hahid

UO

H, G

irls Bra

nch

Page 3: UML (Unified Modeling language)

UML (UNIFIED MODELING LANGUAGE)

o Pseudocode is a way of representing a program in a linear

and algebraic manner.

It simplifies design by eliminating the details of

programming language syntax.

o Graphical representation systems for program design have

also been used:

Flowcharts and structure diagrams for example.

o Unified Modeling Language (UML) is yet another

graphical representation formalism.

UML is designed to reflect and be used with the OOP

philosophy.

3

Sim

ab S

hahid

UO

H, G

irls Bra

nch

Page 4: UML (Unified Modeling language)

UML CLASS DIAGRAM Classes are central to OOP(Object Oriented

Programming), and the class diagram is the easiest of the UML graphical representations to understand and use.

o A class diagram is divided up into three sections:

1. The top section contains the class name.

2. The middle section contains the data specification for

the class.

3. The bottom section contains the actions or methods of

the class.

4

Sim

ab S

hahid

UO

H, G

irls Bra

nch

Page 5: UML (Unified Modeling language)

UML CLASS DIAGRAM(TEMPLATE)

5

Sim

ab S

hahid

UO

H, G

irls Bra

nch

Class NAME will come here

Class VARIABLES will come here

Class FUNCTIONS& constructors will come here

Page 6: UML (Unified Modeling language)

UML CLASS DIAGRAM

o The data specification for each piece of data in a UML

diagram consists of its name, followed by a colon, followed

by its type.

o Each name is preceded by a character that specifies its

access type:

A minus sign (-) indicates private access

A plus sign (+) indicates public access

A sharp (#) indicates protected access

A tilde (~) indicates package access

6

Sim

ab S

hahid

UO

H, G

irls Bra

nch

Page 7: UML (Unified Modeling language)

UML CLASS DIAGRAM

o Each method in a UML diagram is indicated by the name of

the method, followed by its parameter list, a colon (:), and

its returned type.

o The access type of each method is indicated in the same

way as for data.

o A class diagram need not give a complete description of the

class.

o If a given analysis does not require that all the class

members be represented, then those members are not

listed in the class diagram.

o Missing members are indicated with an ellipsis (three

dots).7

Sim

ab S

hahid

UO

H, G

irls Bra

nch

Page 8: UML (Unified Modeling language)

UML CLASS DIAGRAM (EXAMPLE)

8

Sim

ab S

hahid

UO

H, G

irls Bra

nch

Square

- Side : double

- xCoordinate : double

-yCoordinate : double

…+ resize (newSide: double ) : void

+ move (double newx , double newy ) : void

# erase ( ) : void

Class Data Specification

Class member functions

Class Name

Page 9: UML (Unified Modeling language)

UML CLASS DIAGRAM(EXAMPLE)

9

Sim

ab S

hahid

UO

H, G

irls Bra

nch

class Point {

public int XCoord; public int YCoord;

public Point( ) { XCoord=0; YCoord=0; }

public void display() { System.out.println(“X Coordinate = “+ XCoord); System.out.println(“Y Coordinate = “+ YCoord);

}}

Java code for Point class UML class Diagram for Point class

Point+ XCoord : int+ YCoord : int

+ display() : void+ Point()

Page 10: UML (Unified Modeling language)

ACTIVITY 01

10

Sim

ab S

hahid

UO

H, G

irls Bra

nch

public class Cube { int length; int breadth; int height;

public Cube() { length = 0; breadth = 0; height= 0; }

public int getVolum ( ) { return(length*breadth *height); }}

UML class Diagram

Cubelength : intbreadth : intheight : int

+ getVolum( ) : int+ Cube ()

Page 11: UML (Unified Modeling language)

ACTIVITY 02

11

Sim

ab S

hahid

UO

H, G

irls Bra

nch

class Employee {

public String name; public int id; private float salary;

public Employee( String Name, int Id, float Salary) {

name = Name;id = Id;

salary = Salary; }

public void setSalary( float s) { salary = s; }

public float getSalary( ) { return salary; }

}

Page 12: UML (Unified Modeling language)

ACTIVITY 04

12

Sim

ab S

hahid

UO

H, G

irls Bra

nch

Point+ display() : void+ Point()

Is this a valid class diagram ?

Point+ XCoord : int+ YCoord : int

Is this a valid class diagram ?

Java Code

class Point{

public Point(){ }public void display(){ }

}

Java Code

class Point{

public int XCoord ;public int YCoord ;

}

Page 13: UML (Unified Modeling language)

ACTIVITY 05

13

Sim

ab S

hahid

UO

H, G

irls Bra

nch

Point+ display() : void+ Point()

+ XCoord : int+ YCoord : int

Is this a valid class diagram ?

Page 14: UML (Unified Modeling language)

CLASS INTERACTIONS

o Rather than show just the interface of a class, class

diagrams are primarily designed to show the interactions

among classes.

o UML has various ways to indicate the information flow from

one class object to another using different sorts of

annotated arrows.

o UML has annotations for class groupings into packages, for

inheritance, and for other interactions.

o In addition to these established annotations, UML is

extensible.14

Sim

ab S

hahid

UO

H, G

irls Bra

nch

Page 15: UML (Unified Modeling language)

INHERITANCE DIAGRAMS

o An inheritance diagram shows the relationship between a

base class and its derived class(es).

Normally, only as much of the class diagram is shown

as is needed.

Note that each derived class may serve as the base

class of its derived class(es).

o Each base class is drawn above its derived class(es)

An upward pointing arrow is drawn between them to

indicate the inheritance relationship.

15

Sim

ab S

hahid

UO

H, G

irls Bra

nch

Page 16: UML (Unified Modeling language)

A CLASS HIERARCHY IN UML NOTATION

16

Sim

ab S

hahid

UO

H, G

irls Bra

nch

StudentEmployee

StaffUndergraduate Graduate Faculty

Person

Page 17: UML (Unified Modeling language)

INHERITANCE DIAGRAMo The arrows also help in locating method definitions.

o To look for a method definition for a class: Examine the class definition first. If the method is not found, the path of connecting

arrows will show the order and direction in which to search.

Examine the parent class indicated by the connecting arrow.

If the method is still not found, then examine this parent's parent class indicated by the connecting arrow.

Continue until the method is found, or until the top base class is reached.

17

Sim

ab S

hahid

UO

H, G

irls Bra

nch

Page 18: UML (Unified Modeling language)

SOME DETAILS OF CLASS HIERARCHY

18

Sim

ab S

hahid

UO

H, G

irls Bra

nch

+ setName(String newName): void

+ getName( ): String

+ toString( ): String

+ sameName(Person otherPerson): boolean

- name: String

Person

+ set(String newName , int newStudentNumber): void

+ getStudentNumber( ): int

+ setStudentNumber(int newStudentNumber ): void

+ toString( ): String

+ equals(Object otherObject): boolean

- studentNumber: int

Student