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( )
{
[Link](“circle”);
}
}
Class square implements shape
{
Void draw( )
{
[Link](“square”);
}
}
Class Rectangle implements shape
{
Void draw( )
{
[Link](“rectangle”);
}
}
public class SequenceDiagramDemo
{
public static void main(String[] args)
{
Shape circle = new Circle();
[Link]();
Shape rectangle = new Rectangle();
[Link]();
Shape square = new Square();
[Link](); } }
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
[Link]();
//get an object of Rectangle and call its draw method.
Shape rectangle = new Rectangle();
//call draw method of Rectangle
[Link]();
//get an object of Square and call its draw method.
Shape square = new Square();
//call draw method of circle
[Link](); 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.
[Link]
[Link]
Centre for Advance Studies in Engineering Page 5
Course Code: Software Design & Architecture.
Lab 08: UML Diagrams & Code
[Link]
[Link]
Centre for Advance Studies in Engineering Page 6
Course Code: Software Design & Architecture.
Lab 08: UML Diagrams & Code
[Link]
Step 4: Use different Criteria and their combination to filter out persons.
[Link]
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