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