[Design mode] bull market shares will lose money-appearance Mode

Source: Internet
Author: User

I. Overview

Appearance mode is a common software design mode in software engineering. It provides a unified high-level interface for a group of interfaces in the subsystem. Subsystems are easier to use.


2. For example

Investors buy stocks. Most retail investors buy stocks, government bonds, and real estate on their own, and then sell at the right time. In this way, every shareholder needs to know about every stock to make money. That is to say, every shareholder must deal with a lot of stocks.

The more optimized method is that the investors hand over the money to professional financial institutions and make regular profits to achieve a win-win situation. In this way, investors only need to deal with financial institutions. It is called to call a group of stocks through a unified interface of financial institutions.

 

1) Code of a single investor fund

# Include <iostream> using namespace STD; // stock 1 class stock1 {public: // sell stock void offer () {cout <"stock 1 sell" <Endl ;} // buy stock void buy () {cout <"stock 1 buy" <Endl ;}; // stock 2 class stock2 {public: // sell the stock void forward () {cout <"stock 2 sell" <Endl;} // buy the stock void buy () {cout <"stock 2 buy" <Endl ;}; // stock 3 class stock3 {public: // sell stock void seek () {cout <"stock 3 sell" <Endl ;}// buy stock void buy () {cout <"stock 3 buy" <Endl ;}}; // national debt 1 class nationaldebt1 {public: // sell national debt void offer () {cout <"National Debt 1 sell" <Endl ;}// buy national debt void buy () {cout <"National Debt 1 buy" <Endl ;}; // Real Estate 1 class realty1 {public: // sell real estate void coupon () {cout <" 1 "<Endl ;}// buy real estate void buy () {cout <" 1" <Endl ;}}; int main () {stock1 * gu1 = new stock1 (); stock2 * gu2 = new stock2 (); stock3 * gu3 = new stock3 (); nationaldebt1 * nd1 = new nationaldebt1 (); realty1 * rt1 = new realty1 (); gu1-> buy (); gu2-> buy (); gu3-> buy (); nd1-> buy (); rt1-> buy (); gu1-> Queue (); gu2-> Queue (); gu3-> Queue (); nd1-> quit (); rt1-> quit ();}

2) Financial Institution investment (Appearance Model)

Fund's fund management class directly manages stock trading. Investors only need to call the fund management class to buy and sell stocks. This greatly simplifies the financial burden on investors.

# Include <iostream> using namespace STD; // stock 1 class stock1 {public: // sell stock void offer () {cout <"stock 1 sell" <Endl ;} // buy stock void buy () {cout <"stock 1 buy" <Endl ;}; // stock 2 class stock2 {public: // sell the stock void forward () {cout <"stock 2 sell" <Endl;} // buy the stock void buy () {cout <"stock 2 buy" <Endl ;}; // stock 3 class stock3 {public: // sell stock void seek () {cout <"stock 3 sell" <Endl ;}// buy stock void buy () {cout <"stock 3 buy" <Endl ;}}; // national debt 1 class nationaldebt1 {public: // sell national debt void offer () {cout <"National Debt 1 sell" <Endl ;}// buy national debt void buy () {cout <"National Debt 1 buy" <Endl ;}; // Real Estate 1 class realty1 {public: // sell real estate void coupon () {cout <" 1 "<Endl ;}// buy real estate void buy () {cout <" 1" <Endl ;}}; class fund {PRIVATE: stock1 * gu1; stock2 * gu2; stock3 * gu3; nationaldebt1 * nd1; realty1 * rt1; public: Fund () {gu1 = new stock1 (); gu2 = new stock2 (); gu3 = new stock3 (); nd1 = new nationaldebt1 (); rt1 = new realty1 ();} void buyfund () {gu1-> buy (); gu2-> buy (); gu3-> buy (); nd1-> buy (); rt1-> buy ();} void sellfund () {gu1-> callback (); gu2-> callback (); gu3-> callback (); nd1-> callback (); rt1-> round () ;}}; int main () {Fund * jijin = new fund (); jijin-> buyfund (); jijin-> sellfund ();}


Iii. Appearance mode Summary (C #)

Class subsystemone {public void methodone () {console. writeline ("Subsystem Method 1") ;}} class subsystemtwo {public void methodtwo () {console. writeline ("Subsystem Method 2");} class subsystemthree {public void methodthree () {console. writeline ("Subsystem Method 3");} class subsystemfour {public void methodfour () {console. writeline ("Subsystem Method 4") ;}} class facade {subsystemone one; subsystemtwo two; subsystemthree three; subsystemfour four; Public facade () {one = new subsystemone (); two = new subsystemtwo (); three = new subsystemthree (); four = new subsystemfour ();} public void methoda () {console. writeline ("\ n method group A () ----"); one. methodone (); Two. methodtwo (); four. methodfour ();} public void methodb () {console. writeline ("\ n method group B () ----"); Two. methodtwo (); three. methodthree () ;}} int main () {facade = new facade (); facade. methoda (); facade. methodb ();}

4. When to use the appearance Mode

 

1. at the early stage of the design stage, we must consciously separate two different layers, such as the classic three-layer architecture, you need to consider establishing an external facade between the data access layer and the business logic layer, the business logic layer, and the presentation layer Layer. In this way, you can provide a simple interface for complicated subsystems, this greatly reduces coupling.

2. In the development stage, subsystems often become more and more complex due to continuous reconstruction and evolution. By adding a facade, you can provide a simple interface to reduce the dependency between them.

3. when maintaining a legacy large system, it may be very difficult to maintain and expand. You can develop a facade class for the new system, to provide clear and simple interfaces for the design of rough or highly complex legacy code, so that the new system can interact with the facade object, and the facade and legacy code can interact with all the complicated work.

 

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.