0% found this document useful (0 votes)
90 views

Lab 08 (UML Diagrams & Code)

This document discusses UML diagrams and how to convert between UML diagrams and code. It provides examples of converting class diagrams, sequence diagrams, and code to class, sequence, and class diagrams. It also discusses creating criteria classes and interfaces based on a class diagram for filtering person objects.

Uploaded by

Wasie Urrahman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

Lab 08 (UML Diagrams & Code)

This document discusses UML diagrams and how to convert between UML diagrams and code. It provides examples of converting class diagrams, sequence diagrams, and code to class, sequence, and class diagrams. It also discusses creating criteria classes and interfaces based on a class diagram for filtering person objects.

Uploaded by

Wasie Urrahman
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Course Code: Software Design & Architecture.

Lab 08: UML Diagrams & Code

UML Eléments vs Java :

The following simple states that class A uses/depends on class B in some way. It’s a way to
broadly.

Centre for Advance Studies in Engineering Page 1


Course Code: Software Design & Architecture.
Lab 08: UML Diagrams & Code

Code to Class diagram:

Interface shape
{
Void draw( )
}
Class circle implements shape
{
Void draw( )
{
System.out.println(“circle”);
}
}

Class square implements shape


{
Void draw( )
{
System.out.println(“square”);
}
}

Class Rectangle implements shape


{
Void draw( )
{
System.out.println(“rectangle”);
}
}

public class SequenceDiagramDemo


{
public static void main(String[] args)
{
Shape circle = new Circle();
circle.draw();
Shape rectangle = new Rectangle();
rectangle.draw();
Shape square = new Square();
square.draw(); } }

Centre for Advance Studies in Engineering Page 2


Course Code: Software Design & Architecture.
Lab 08: UML Diagrams & Code

Code to Sequence diagram:

public class SequenceDiagramDemo


{
public static void main(String[] args)
{
//get an object of Circle and call its draw method.
Shape circle = new Circle();
//call draw method of Circle
circle.draw();
//get an object of Rectangle and call its draw method.
Shape rectangle = new Rectangle();
//call draw method of Rectangle
rectangle.draw();
//get an object of Square and call its draw method.
Shape square = new Square();
//call draw method of circle
square.draw(); Sequence Diagram to Code:
}

Centre for Advance Studies in Engineering Page 3


Course Code: Software Design & Architecture.
Lab 08: UML Diagrams & Code

Class Diagram to Code:

Step 1: Create Person Class:

Centre for Advance Studies in Engineering Page 4


Course Code: Software Design & Architecture.
Lab 08: UML Diagrams & Code

Step 2: Create an interface for Criteria

Step 3: Create concrete classes implementing the Criteria interface.


CriteriaMale.java

CriteriaFeMale.java

Centre for Advance Studies in Engineering Page 5


Course Code: Software Design & Architecture.
Lab 08: UML Diagrams & Code

CriteriaSingle.java

AndCriteria.java

Centre for Advance Studies in Engineering Page 6


Course Code: Software Design & Architecture.
Lab 08: UML Diagrams & Code

OrCriteria.java

Step 4: Use different Criteria and their combination to filter out persons.
CriteriaPatternDemo.java

Centre for Advance Studies in Engineering Page 7


Course Code: Software Design & Architecture.
Lab 08: UML Diagrams & Code

Practice Question:

Covert following sequence diagram to code:

Centre for Advance Studies in Engineering Page 8

You might also like