ООП для чайников. Паттерны проектирования. Фасад (facade)

Еще один паттерн из группы структурирующих, – фасад. Фасад предоставляет унифицированный интерфейс, “оборачивая” собой подсистему. Им пользуются в случае если необходимо изолировать клиента от “разухабистого” API подсистемы, упрощая его и сокращая количество объектов о которых должен знать клиент. Фасад может упростить переносимость кода между разными платформами или подсистемами.

Вот как выглядит Фасад на диаграмме:

facade

Простой пример, реализующий Фасад на Python:

class Tree:
    
    def grow(self):
        print("grow tree")
    
class Child:
    
    def born(self):
        print("born child")
    
class House:
    
    def build(self):
        print("build house")
    
    
class TheMenFacade:
    
    def __init__(self):
        self._tree = Tree()
        self._child = Child()
        self._house = House()
    
    def growTree(self):
        self._tree.grow()
        
    def bornChild(self):
        self._child.born()
        
    def buildHouse(self):
        self._house.build()
        
if __name__ == '__main__':
    
    print 'Content-Type: text/plain'
    print ''    
    
    facade = TheMenFacade()
    facade.bornChild()
    facade.buildHouse()
    facade.growTree()

--------------

born child
build house
grow tree

Site Footer

Sliding Sidebar

About Me

About Me

For whom this blog for?

For those who are interested in modern Internet technologies, IT business, startups, management, quality control, personal effectiveness, motivation. Here I write about what is interesting, about problems I faced and solutions I found. I hope it will be interesting to you either.

What motivates me to write?

The desire to improve, to study deeper topics that interest me. Find people with similar problems and tasks, together look for ways out and solutions.

Feel free to contact if you have anything to say to me

Old Flash site with my artistic works and misuc.