Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 15

University of Computer Studies

Unified Modeling Language (UML)


Modeling With Objects

Daw Nan Nu Nu Kyi


Lecturer
Faculty of Information Science
Modeling with Objects Unified Modeling Language

The Object Model Associations

Classes And Objects Message Passing

Object Properties Polymorphism

Avoiding Data Replication Dynamic Binding

2
Links

15
Modeling with Objects Unified Modeling Language

Parts Information in CatalogueEntry

CatalogueEntry Java Class


public class CatalogueEntry {
private String name;
private long num;
private double cost;
public CatalogueEntry(String nm, long num, double cst)
{
name=nm;
num=num;
cost=cst;
}
public String getName()
{
return name;
}
public long getNum()
{
return num;
}
public double getCost()
Figure 2.3 . Parts described by {
3 return cost;

15
catalogue entries }}
Modeling with Objects Unified Modeling Language

Links

Create CatalogueEntry object “screw” and Part


Part Java Class
objects “s1” and “s2”

public class Part {


CatalogueEntry screw= new CatalogueEntry ("screw",28834,
private CatalogueEntry entry;
0.02);
reference
public Part (CatalogueEntry e)
Part s1= new Part(screw);
{
Part s2= new Part(screw);
entry=e;

4

15
Modeling with Objects Unified Modeling Language

Links(Cont’d)

• References can be shown in UML by drawing a link between two objects


(CatalogueEntry and Parts)

Figure. 2.4 Links between objects (Object Diagram)

• Arrowhead indicates that it can only traversed, or navigated, in one direction

5

15
Modeling with Objects Unified Modeling Language

Object Diagrams

• Shows objects and links between them


• Information is recorded in two ways
 held explicitly as attribute values in objects
 held purely structurally, by means of links

6

15
Modeling with Objects Unified Modeling Language

The Object Model Associations

Classes And Objects Message Passing

Object Properties Polymorphism

Avoiding Data Replication Dynamic Binding

Links
7

15
Modeling with Objects Unified Modeling Language

Associations

• In UML, a data relationship between classes is called an association.


• Links are instances of associations
• Objects are instances of classes
• Multiplicity constraint states how many instances a given object can be linked to
at any one time

8
ㅡ Figure 2.5 An association between two classes (Class Diagram)
15
Modeling with Objects Unified Modeling Language

Class Diagrams

• Class diagrams contain classes and associations


• Specify in a more general way
• Object diagrams are referred to as being instances of class diagrams

9

15
Modeling with Objects Unified Modeling Language

The Object Model Associations

Classes And Objects Message Passing

Object Properties Polymorphism

Avoiding Data Replication Dynamic Binding

10
Links

15
Modeling with Objects Unified Modeling Language

Object Interaction

Create cost method in Part Java Create part object “s1” and find out its cost
Class in Client Java Class

public class Part Part s1=new Part(screw);


{ double s1cost=s1.cost();
public double cost()
{
return entry.getCost();
}
private CatalogueEntry entry;
}

11

15
Modeling with Objects Unified Modeling Language

Message Passing

• UML represents method calls as message that are sent from one object to
another object method

reference variable
Figure 2.6. Sending a message

• Messages are shown on object diagrams as labelled arrows adjacent to links

12

15
Modeling with Objects Unified Modeling Language

Message Passing Cont’d

returned value

Figure 2.7 Finding the cost of a part “s1”


• The value returned is written before the message name and separated from
it by the assignment symbol ‘:=’
• The object that sent the message waits until control returns before
13

continuing with its own processing
15
Modeling with Objects Unified Modeling Language

Reference Text Book

• Mark Priestley , Practical Object-


Oriented Design with UML ,
Second Edition

14

15
Modeling with Objects Unified Modeling Language

Next Lecture

Polymorphism

15

15

You might also like