File tree 1 file changed +62
-0
lines changed
structural_design_pattern/facade 1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ //!
2
+ //! BAD EXAMPLE FROM TUTORIAL POINT
3
+ //! Source:: https://www.tutorialspoint.com/design_pattern/facade_pattern.htm
4
+
5
+ // ShapeMaker class uses the concrete classes to delegate user calls to these classes.
6
+ // main, our demo class, will use ShapeMaker class to show the results.
7
+
8
+ // Step 1
9
+ // Create an interface.
10
+ abstract class IShape {
11
+ void draw ();
12
+ }
13
+
14
+ // Step 2
15
+ // Create concrete classes implementing the same interface.
16
+ class Rectangle implements IShape {
17
+ @override
18
+ void draw () => print ("Rectangle::draw()" );
19
+ }
20
+
21
+ class Square implements IShape {
22
+ @override
23
+ void draw () => print ("Square::draw()" );
24
+ }
25
+
26
+ class Circle implements IShape {
27
+ @override
28
+ void draw () => print ("Circle::draw()" );
29
+ }
30
+
31
+ // Step 3
32
+ // Create a facade class.
33
+ class ShapeMaker {
34
+ IShape _circle;
35
+ IShape _rectangle;
36
+ IShape _square;
37
+
38
+ ShapeMaker ()
39
+ : _circle = Circle (),
40
+ _rectangle = Rectangle (),
41
+ _square = Square ();
42
+
43
+ void drawCircle () => _circle.draw ();
44
+ void drawRectangle () => _rectangle.draw ();
45
+ void drawSquare () => _square.draw ();
46
+ }
47
+
48
+ // Step 4
49
+ // Use the facade to draw various types of shapes.
50
+ void main () {
51
+ ShapeMaker shapeMaker = ShapeMaker ();
52
+
53
+ shapeMaker.drawCircle ();
54
+ shapeMaker.drawRectangle ();
55
+ shapeMaker.drawSquare ();
56
+ }
57
+
58
+ // Step 5
59
+ // output.
60
+ // Circle::draw()
61
+ // Rectangle::draw()
62
+ // Square::draw()
You can’t perform that action at this time.
0 commit comments