标签:out cas over system override ati str font ignore
工厂设计模式
public interface Shape {
void draw();
}
public class Rectangle implements Shape{
@Override
public void draw() {
System.out.println("我画出了一个矩形");
}
}
public class Circle implements Shape{
@Override
public void draw() {
System.out.println("我画出了一个圆");
}
}
public class Square implements Shape {
@Override
public void draw() {
System.out.println("我画出了一个正方形");
}
}
public class ShapeFactory {
public Shape getShape(String shape){
if(shape == null){
return null;
}else if(shape.equalsIgnoreCase("Circle")){
return new Circle();
}else if(shape.equalsIgnoreCase("Rectangle")){
return new Rectangle();
}else if(shape.equalsIgnoreCase("Square")){
return new Square();
}
return null;
}
}
public class TestShape {
public static void main(String[] args){
ShapeFactory sf = new ShapeFactory();
Shape shape1 = sf.getShape("Circle");
shape1.draw();
Shape shape2 = sf.getShape("Rectangle");
shape2.draw();
Shape shape3 = sf.getShape("Square");
shape3.draw();
}
}
单例设计模式
代理设计模式
观察者设计模式
MVC模式
标签:out cas over system override ati str font ignore
原文地址:https://www.cnblogs.com/yangHS/p/10735664.html