-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshape_maker.dart
More file actions
62 lines (51 loc) · 1.3 KB
/
shape_maker.dart
File metadata and controls
62 lines (51 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//!
//! BAD EXAMPLE FROM TUTORIAL POINT
//! Source:: https://www.tutorialspoint.com/design_pattern/facade_pattern.htm
// ShapeMaker class uses the concrete classes to delegate user calls to these classes.
// main, our demo class, will use ShapeMaker class to show the results.
// Step 1
// Create an interface.
abstract class IShape {
void draw();
}
// Step 2
// Create concrete classes implementing the same interface.
class Rectangle implements IShape {
@override
void draw() => print("Rectangle::draw()");
}
class Square implements IShape {
@override
void draw() => print("Square::draw()");
}
class Circle implements IShape {
@override
void draw() => print("Circle::draw()");
}
// Step 3
// Create a facade class.
class ShapeMaker {
IShape _circle;
IShape _rectangle;
IShape _square;
ShapeMaker()
: _circle = Circle(),
_rectangle = Rectangle(),
_square = Square();
void drawCircle() => _circle.draw();
void drawRectangle() => _rectangle.draw();
void drawSquare() => _square.draw();
}
// Step 4
// Use the facade to draw various types of shapes.
void main() {
ShapeMaker shapeMaker = ShapeMaker();
shapeMaker.drawCircle();
shapeMaker.drawRectangle();
shapeMaker.drawSquare();
}
// Step 5
// output.
// Circle::draw()
// Rectangle::draw()
// Square::draw()