Design Mode C ++ implementation 8: appearance Mode

Source: Internet
Author: User

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;}


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.