ASE Assignment 2 PDF
ASE Assignment 2 PDF
Q1:
method?
2- Draw a Use case Scenario for at least three examples for system architectures for three
different systems?
3- What are the creational design patterns? Write down each pattern with java code
examples?
Creational design patterns are a set of design patterns that aim to handle object creation
mechanisms, allowing for the creation of objects in a way that suits the current situation. There
are five main creational design patterns available, which are:
1. Singleton Pattern
The Singleton Pattern makes sure that only one instance of a class can be created, and provides a
universal access point to that instance. This pattern is useful in cases where there is a
requirement to control access to a shared resource or limit the number of instances of a class.
Java Code:
private Singleton() {}
public static synchronized Singleton getInstance() {
if(instance == null) {
return instance;
2. Factory Pattern The Factory Pattern offers a way to generate objects without revealing
the creation logic to the client. This pattern is useful in cases where different objects need
void draw();
@Override
System.out.println("Drawing a rectangle");
}
}
@Override
System.out.println("Drawing a circle");
if(shapeType == null) {
return null;
if(shapeType.equalsIgnoreCase("CIRCLE")) {
} else if(shapeType.equalsIgnoreCase("RECTANGLE")) {
return null;
3. Abstract Factory Pattern The Abstract Factory Pattern defines an interface for producing
families of related or dependent objects without specifying their concrete classes. This
pattern is useful in cases where objects that are related or dependent on each other need to
be created.
void draw();
@Override
System.out.println("Drawing a rectangle");
}
public class Circle implements Shape {
@Override
System.out.println("Drawing a circle");
void fill();
@Override
}
public class Blue implements Color {
@Override
@Override
if(shapeType == null) {
return null;
}
if(shapeType.equalsIgnoreCase("CIRCLE")) {
} else if(shapeType.equalsIgnoreCase("RECTANGLE")) {
return null;
@Override
return null;
@Override
return null;
}
@Override
if(colorType == null) {
return null;
if(colorType.equalsIgnoreCase("RED")) {
} else if(colorType.equalsIgnoreCase("BLUE")) {
Q2:
Write down short notes on each with of the following with code examples.
• Abstract Method
• Abstract class
• Constructors
• Concrete class
• Interface
Abstract Method: An abstract method is a method without implementation that must be
implemented in a subclass.
System.out.println("Drawing a rectangle");
System.out.println("Drawing a circle");
Abstract Class: An abstract class is a class that cannot be instantiated and may contain
super(name);
super(name);
}
class Person {
this.name = name;
this.age = age;
return name;
return age;
}
Concrete Class: A concrete class is a class that can be instantiated and may or may not
class Car {
this.make = make;
this.model = model;
return make;
return model;
}
}
interface Shape {
double getArea();
this.width = width;
this.height = height;
}
class Circle implements Shape {
this.radius = radius;