Design Pattern-appearance Pattern

Source: Internet
Author: User

Facade)

Definition: provides a consistent interface for a group of interfaces in the subsystem. This mode defines a high-level interface, which makes the subsystem easier to use.

For example, the new stockholders can easily lose money if they do not have enough knowledge about the stock ownership. After all, they do not have knowledge about the stock. However, if the stockholders hand over the funds to professional managers for management, then they do not need to participate in the specific purchase and sale of the shares, which can be done by the Fund Company.

The investment fund code is as follows:

Namespace _ 12. _ 3 _ investment fund code {// specific stock, national debt, real estate class // stock 1 class stock1 {// sell stock public void offer () {console. writeline ("stock 1 sold");} // buy stock public void buy () {console. writeline ("stock 1 buy") ;}/// stock 2 class stock2 {// sell stock public void offer () {console. writeline ("stock 2 sold");} // buy stock public void buy () {console. writeline ("stock 2 buy") ;}/// stock 3 class stock3 {// sell stock public void offer () {console. writeline ("stock 3 sold");} // buy stock P Ublic void buy () {console. writeline ("stock 3 buy"); }}// national debt 1 class nationaldebt1 {// sell national debt public void coupon () {console. writeline (" 1 sold");} // buy public void buy () {console. writeline ("National Debt 1 buy") ;}// Real Estate 1 class realty1 {// sell real estate public void buy () {console. writeline ("property 1 sold");} // buy real estate public void buy () {console. writeline ("House 1 buy") ;}// the fund category is as follows // fund category. It needs to understand the methods or attributes of all stocks or other investment methods for combination, for external calls. Class fund {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 ();} public void buyfund () {gu1.buy (); gu2.buy (); gu3.buy (); nd1.buy (); rt1.buy ();} public void sellfund () {gu1.20.(); gu2.20.(); gu3.20.(); nd1.20.(); rt1.20 ();}} // The client is as follows // the user does not need to understand the shares You can even know nothing about the stock. If you buy a fund, you will go home and go to bed. After a while, you will be able to redeem the stock and get a lot of money. Fund companies are responsible for buying and selling stocks. Class program {static void main (string [] ARGs) {fund jijin = new fund (); // The fund purchases jijin. buyfund (); // Fund Redemption jijin. sellfund (); console. read ();}}}
Advantages and disadvantages of appearance mode:
Advantages:
(1) It shields subsystem components from the client, reduces the number of objects to be processed by the client, and makes it easier to use the subsystem. By introducing the appearance mode, the client code becomes very simple and there are few objects associated with it.
(2) it implements the loose coupling between the subsystem and the client, so that the subsystem changes do not affect the client that calls it. You only need to adjust the appearance class.
(3) Modifications to a sub-system have no impact on other sub-systems, and internal changes in the sub-system do not affect the appearance objects.
Disadvantages:
(1) The client cannot directly use the sub-system class. If too many restrictions are imposed on the client to access the sub-system class, the variability and flexibility are reduced.
(2) If the design is inappropriate, adding a new subsystem may need to modify the source code of the appearance class, which violates the open and closed principle.


Design Pattern-appearance Pattern

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.