Big talk involves pattern Python implementation-appearance mode

Source: Internet
Author: User

Appearance mode (facade pattern): Provides a consistent interface for a set of interfaces in a subsystem that defines a high-level interface that makes the subsystem easier to use

Here is a demo of the appearance mode:

1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 4 __author__='Andy'5 """6 Liar design Mode7 design mode-appearance mode8 facade_pattern.py9 appearance mode (facade pattern): Provides a consistent interface for a set of interfaces in a subsystem that defines a high-level interface that makes the subsystem easier to useTen """ One #Appearance class A classFund (object): -  -     def __init__(self): theSelf.stocka =Stocka () -SELF.STOCKB =stockb () -Self.realty =Realty () -  +     defBuy (self): - self.stocka.buy () + self.stockb.buy () A self.realty.buy () at  -     defSell (self): - Self.stocka.sell () - Self.stockb.sell () - Self.realty.sell () -  in #investment stocks A class - classStocka (object): to  +     defBuy (self): -         Print 'buy Stocka' the  *     defSell (self): $         Print 'Sell Stocka'Panax Notoginseng #Investment Stocks Class B - classstockb (object): the  +     defBuy (self): A         Print 'buy stockb' the  +     defSell (self): -         Print 'Sell stockb' $  $ #investing in Real estate - classRealty (object): -  the     defBuy (self): -         Print 'buy Realty'Wuyi  the     defSell (self): -         Print 'Sell Realty' Wu  -  About  $ if __name__=="__main__": -  -fund =Fund () - fund.buy () AFund.sell ()

The design of the above class is as follows:

The Fund class needs to know the functionality of the subsystem classes so that the appropriate client requests are sent to the appropriate subsystem objects, making the subsystem easier to use


Andy
Source: http://www.cnblogs.com/onepiece-andy/
The copyright of this article is owned by the author and the blog Park, welcome reprint, but without the author's consent must be in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.

Big talk involves pattern Python implementation-appearance mode

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.