Appearance (facade) mode [Python version]

Source: Internet
Author: User

Appearance (facade) Mode: Provides a consistent interface for a group of interfaces in the subsystem.

-- This mode defines a high-level interface, which makes this subsystem easier to use.

Differences from other models: Similar to the combined version of "simple factory mode + policy mode", the appearance class interface is not a simple call of the corresponding interface of the function class, but encapsulated into a new interface.

Use Cases: To maintain a legacy large system, it may be very difficult to maintain and expand, but it contains very important functions. New Development must depend on it, in this way, the appearance facade class is added, and a clear and simple interface is encapsulated for the system to allow the new system to interact with the facade object, and the facade to interact with the legacy code in all the complicated work.

# Encoding = UTF-8 ## by Panda # facade def printinfo (Info): Print Unicode (Info, 'utf-8 '). encode ('gbk') Class stock1 (): name = 'stock 1' def buy (Self): printinfo ('buy '+ self. name) def evaluate (Self): printinfo ('sell' + self. name) Class stock2 (): name = 'stock 2' def buy (Self): printinfo ('buy '+ self. name) def evaluate (Self): printinfo ('sell' + self. name) Class nationdebt1 (): name = 'national debt 1' def buy (Self): printinfo ('shop' + self. name) def evaluate (Self): printinfo ('sell' + self. name) Class realty1 (): name = 'realestate 1' def buy (Self): printinfo ('buy '+ self. name) def evaluate (Self): printinfo ('sell' + self. name) # fund class fund (): gu1 = none gu2 = none nd1 = none rt1 = none def _ init _ (Self): Self. gu1 = stock1 () self. gu2 = stock2 () self. nd1 = nationdebt1 () self. rt1 = realty1 () def buyfund (Self): Self. gu1.buy () self. gu2.buy () self. nd1.buy () self. rt1.buy () def sellfund (Self): Self. gu1.20.() self. gu2.133 () self. nd1.merge () self. rt1.parse () def clientui (): myfund = Fund () myfund. buyfund () myfund. sellfund () returnif _ name _ = '_ main _': clientui ();

Class Diagram:

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.