例如我有一个接口和一堆类如下
public interface Drawable{
void draw(); // draws something on screen for example.
}
abstract class Shape implements Drawable {...}
class Circle extends Shape{...} // assume that draw() is implemented in both classes.
class Square extends Shape{...} // ...
现在,如果我有一个主类并执行以下操作:
class Main{
Shape s1 = new Circle();
s1.draw(); // assume that this will draw a circle.
s1 = new Square();
s1.draw(); //assume that this will draw a square.
}
我在这里使用设计模式吗?或者这只是标准的多态性?如果这是一种设计模式,那么它叫什么?