Design Mode C ++ implementation 8: appearance Mode
Facade: provides a consistent interface for a group of interfaces in the subsystem. This mode defines a high-level interface, which is easier to use at all times.
Use Cases: first, in the initial stage of design, we should consciously separate the two layers. For example, for a classic three-tier structure, you need to consider establishing a Facade between the data access layer, business logic layer, business logic layer, and presentation layer and layer. Secondly, in the development stage, subsystems are often increasingly complicated due to the continuous reconstruction and evolution. Many small classes will be generated in most modes. This is a good thing, however, it also makes it difficult for external users to call their programs. With the addition of Facade, a simple interface can be provided to reduce their dependencies. Third, maintaining a legacy system is that it may be very difficult to maintain and expand, but because it contains very important functions, new demand development must rely on it. In this case, the appearance mode is very suitable.
# Ifndef FACADE_H # define FACADE_H # include
Using namespace std; class Stock1 {public: void Buy () {cout <"Buy stock 1 \ n";} void round () {cout <"sell stock 1 \ n" ;}}; class Stock2 {public: void Buy () {cout <"Buy stock 2 \ n ";} void evaluate () {cout <"Sell stock 2 \ n" ;}}; class Stock3 {public: void Buy () {cout <"buy stock 3 \ n";} void buy () {cout <"Sell stock 3 \ n" ;}}; class NationalDebt1 {public: void Buy () {cout <"Buy national debt 1 \ n";} void hour () {cout <"Sell national debt 1 \ n ";}}; class Reality1 {public: void Buy () {cout <"Buy real estate 1 \ n";} void Merge () {cout <"selling real estate 1 \ n" ;}}; class Fund {Stock1 st1; Stock2 st2; Stock3 st3; NationalDebt1 Nd; Reality1 Re; public: void Buy () {st1.Buy (); st2.Buy (); st3.Buy (); Nd. buy (); Re. buy ();} void Merge () {st1.Sell (); st2.Sell (); st3.Sell (); Nd. round (); Re. round () ;};# endif
#include"Facade.h"int main(){Fund Fd;Fd.Buy();Fd.Sell();return 0;}