3 fa C Ade mode 3.1 Overview
Also known as appearance mode. This mode is a very common model in reality. For example, the design of a car is complicated in a car, but it is very easy to drive a car. Why? Because the car designer "encapsulates" the complex part of the car in the car, only provides easy-to-use steering wheel, brakes and fuel for you to control the car. This is the fa c Ade model. We need a simpler way to use a complicated thing and meet our needs.
3.2 Design
So how can we simply use a complicated thing? You only need this complicated item to provide the functions I need. For example, driving a car forward is a very complex system for the car itself. It needs to Burn Gasoline, use an engine to form power, and then transmit it to the tire through the bearing shaft to make the tire roll, this allows the car to move forward. If we need to control the operation of these components inside the car, it is estimated that no one can learn to drive. So what should we do? It's easy. A car provides a function-fuel. We only need to step down and the car will move forward. In this way, everyone can easily learn to drive.
3.3 implementation
UML diagram:
None
The sample code is as follows:
1 using system;
2
3 namespace example
4 {
5/** // <summary>
6 // example
7 /// </Summary>
8 Class Example
9 {
10/*** // <summary>
11 /// main entry point of the application.
12 /// </Summary>
13 [stathread]
14 static void main (string [] ARGs)
15 {
16 usecar = new usecar ();
17 usecar. Drive (); // drive
18}
19/** // <summary>
20 // complex cars
21 /// </Summary>
22 public class car
23 {
24 public car (){}
25
26 Public void oil ()
27 {
28 console. writeline ("come on to the engine ...... ");
29}
30 public void motor ()
31 {
32 console. writeline ("engine ...... ");
33}
34 public void transmission ()
35 {
36 console. writeline ("power transmission ...... ");
37}
38 public void tire ()
39 {
40 console. writeline ("rolling ...... ");
41}
42 // other methods ......
43}
44/*** // <summary>
45 // use a car
46 /// </Summary>
47 // <remarks>
48 // use the facade mode and use a simple drive to encapsulate complex actions (oil, motor…) inside the car ......)
49 // The user can use this simple function (drive) to control the vehicle forward.
50 /// </remarks>
51 public class usecar
52 {
53 public usecar (){}
54
55 public void drive ()
56 {
57 console. writeline ("ready to drive! ");
58 car = new car ();
59 car. Oil ();
60 car. Motor ();
61 car. Transmission ();
62 car. Tire ();
63 console. writeline ("driving! ");
64}
65}
66}
67}
68