dart_in_action/23_design_pattern_facade.dart

77 lines
1.5 KiB
Dart
Raw Normal View History

2019-03-27 10:55:27 +08:00
/**
Facade Pattern
使使
访
使
1"接待员"
2
*/
main(List<String> args) {
ShapeMaker shapeMaker = new ShapeMaker();
shapeMaker.drawCircle();
shapeMaker.drawRectangle();
shapeMaker.drawSquare();
}
//////////////////////////////////////////////////////////////////
///
/// 创建一个接口
///
abstract class Shape {
void draw();
}
///
/// 创建实现接口的实体类
///
class Rectangle implements Shape {
@override
void draw() {
print("Rectangle::draw()");
}
}
class Square implements Shape {
@override
void draw() {
print("Square::draw()");
}
}
class Circle implements Shape {
@override
void draw() {
print("Circle::draw()");
}
}
///
/// 创建一个外观类
///
class ShapeMaker {
Shape circle;
Shape rectangle;
Shape square;
ShapeMaker() {
circle = Circle();
rectangle = Rectangle();
square = Square();
}
void drawCircle() {
circle.draw();
}
void drawRectangle() {
rectangle.draw();
}
void drawSquare() {
square.draw();
}
}