Facade Design Pattern in Python…

This design pattern provides a simplified and unified interface to hide the inner complexities of several subsystems or libraries.

As most of the time, the user of a subsystem does not want to know about the internal complexities. He just wants a simp…


This content originally appeared on DEV Community and was authored by Somenath Mukhopadhyay

This design pattern provides a simplified and unified interface to hide the inner complexities of several subsystems or libraries.

As most of the time, the user of a subsystem does not want to know about the internal complexities. He just wants a simplified interface to use the subsystem. Subsystems become complex as they evolve. A facade can provide this simplified interface to the users of the subsystem.

The main participants of the Facade design pattern are

- facade itself

- and the several subsystems

The subsystems have no knowledge about the facade - meaning they don't keep any reference to the facade.

Let me give you an example.

Suppose there are many geometrical shapes whose drawing functionalities are complex and each one must be drawn differently. But the client really does not want to go into that complexity.

Here comes the facade pattern in the rescue. This pattern will give a single method called drawShapes which will take care of all the internal complexity of the individual shapes.

Here goes the source code of the example.

from abc import ABC, abstractmethod

class Shape(ABC):
    """
    Abstract base class for all shapes.
    """
    @abstractmethod
    def draw(self):
        pass

class Circle(Shape):
    """
    Concrete class for a Circle.
    """
    def draw(self):
        print("Special method to draw a circle")

class Rectangle(Shape):
    """
    Concrete class for a Rectangle.
    """
    def draw(self):
        print("Special method to draw a rectangle")

class Triangle(Shape):
    """
    Concrete class for a Triangle.
    """
    def draw(self):
        print("Special method to draw a triangle")

class FacadeToShape:
    """
    The Facade provides a simplified interface to the complex subsystem of shapes.
    """
    def __init__(self, circle, rectangle, triangle):
        self.circle = circle
        self.rectangle = rectangle
        self.triangle = triangle

    def draw_circle(self):
        """Draws a circle using the subsystem."""
        self.circle.draw()

    def draw_rectangle(self):
        """Draws a rectangle using the subsystem."""
        self.rectangle.draw()

    def draw_triangle(self):
        """Draws a triangle using the subsystem."""
        self.triangle.draw()

    def draw_shapes(self):
        """Draws all shapes in a predefined order."""
        self.draw_circle()
        self.draw_triangle()
        self.draw_rectangle()

if __name__ == '__main__':
    # The client code interacts with the Facade instead of the individual shapes.
    facade_to_shape = FacadeToShape(Circle(), Rectangle(), Triangle())
    facade_to_shape.draw_shapes()


This content originally appeared on DEV Community and was authored by Somenath Mukhopadhyay


Print Share Comment Cite Upload Translate Updates
APA

Somenath Mukhopadhyay | Sciencx (2025-09-07T07:10:19+00:00) Facade Design Pattern in Python…. Retrieved from https://www.scien.cx/2025/09/07/facade-design-pattern-in-python/

MLA
" » Facade Design Pattern in Python…." Somenath Mukhopadhyay | Sciencx - Sunday September 7, 2025, https://www.scien.cx/2025/09/07/facade-design-pattern-in-python/
HARVARD
Somenath Mukhopadhyay | Sciencx Sunday September 7, 2025 » Facade Design Pattern in Python…., viewed ,<https://www.scien.cx/2025/09/07/facade-design-pattern-in-python/>
VANCOUVER
Somenath Mukhopadhyay | Sciencx - » Facade Design Pattern in Python…. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/09/07/facade-design-pattern-in-python/
CHICAGO
" » Facade Design Pattern in Python…." Somenath Mukhopadhyay | Sciencx - Accessed . https://www.scien.cx/2025/09/07/facade-design-pattern-in-python/
IEEE
" » Facade Design Pattern in Python…." Somenath Mukhopadhyay | Sciencx [Online]. Available: https://www.scien.cx/2025/09/07/facade-design-pattern-in-python/. [Accessed: ]
rf:citation
» Facade Design Pattern in Python… | Somenath Mukhopadhyay | Sciencx | https://www.scien.cx/2025/09/07/facade-design-pattern-in-python/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.