Commit d0ffed36 authored by ElaFHNW's avatar ElaFHNW
Browse files

adapter pattern

parent 7b4717b1
package designPattern.Adapter;
public class Circle implements Shape {
@Override
public void draw() {
System.out.println("Drawing Circle");
}
@Override
public void resize() {
System.out.println("Resizing Circle");
}
@Override
public String description() {
return "Circle object";
}
@Override
public boolean isHide() {
return false;
}
}
\ No newline at end of file
package designPattern.Adapter;
import java.util.ArrayList;
import java.util.List;
public class Drawing {
List<Shape> shapes = new ArrayList<Shape>();
public Drawing() {
super();
}
public void addShape(Shape shape) {
shapes.add(shape);
}
public List<Shape> getShapes() {
return new ArrayList<Shape>(shapes);
}
public void draw() {
if (shapes.isEmpty()) {
System.out.println("Nothing to draw!");
} else {
shapes.stream().forEach(shape -> shape.draw());
}
}
public void resize() {
if (shapes.isEmpty()) {
System.out.println("Nothing to resize!");
} else {
shapes.stream().forEach(shape -> shape.resize());
}
}
}
\ No newline at end of file
package designPattern.Adapter;
public class Main {
public static void main(String[] args) {
System.out.println("Creating drawing of shapes...");
Drawing drawing = new Drawing();
drawing.addShape(new Rectangle());
drawing.addShape(new Circle());
System.out.println("Drawing...");
drawing.draw();
System.out.println("Resizing...");
drawing.resize();
}
}
\ No newline at end of file
package designPattern.Adapter;
public class Rectangle implements Shape {
@Override
public void draw() {
System.out.println("Drawing Rectangle");
}
@Override
public void resize() {
System.out.println("Resizing Rectangle");
}
@Override
public String description() {
return "Rectangle object";
}
@Override
public boolean isHide() {
return false;
}
}
\ No newline at end of file
package designPattern.Adapter;
public interface Shape {
void draw();
void resize();
String description();
boolean isHide();
}
\ No newline at end of file
package designPattern.Adapter;
// complete this class
public class Triangle {
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment