Programmation Orientée Objet en Python
  • Back to Main Website
  • Home
  • Introduction: Histoire et Concepts
    • Introduction: Histoire et Concepts
    • Histoire de la programmation
    • Première Structuration des données
    • Naissance de la POO
    • Python: tout n’est qu’objet
    • Python : Simplicité des objets et performance sous-jacente
    • Classes en Python : Concepts fondamentaux

    • Travaux Pratiques
    • Construire sa propre Liste
    • Construire son propre DataFrame
  • Encapsulation, Héritage, Composition et Dunder
    • Encapsulation, Heritage, Composition et Dunder
    • Encapsulation en Python
    • Héritage en Python : Concept et intérêt
    • Héritage vs Composition
    • Méthodes Dunder en Python
    • Python call Method: A Fun Exploration

    • Travaux Pratiques
    • TP: Heritage avec le pricing d’option
    • TP : Ajouter des méthodes dunder à DataFrameSimple
    • TP : Étendre la classe Liste avec des méthodes dunder
    • TP: Dunder Method with Tensor for Automatic Differentiation
  • Polymorphisme et Surcharge
    • Polymorphisme et Surcharge
    • Polymorphism in Object-Oriented Programming
    • Polymorphism in Python: Function Overloading and Type Checking
    • Class Creation: Standard vs type()
    • Type Hinting, Typing Module, and Linters in Python
    • Abstract Classes
    • Protocol Classes

    • Travaux Pratiques
    • TP
  • Decorators
    • Design Patterns
    • The decorator pattern
    • Decorator Practically
    • Built-in Decorators and Standard Library Decorators in Python
    • Practical Decorators in Python Libraries

    • Travaux Pratiques
    • TP: Monte Carlo Option Pricing with Decorators
    • TP: Optimizing Heston Model Monte Carlo Simulation
  • Project Management and Packaging
    • Project and Package
    • Organizing Python Projects
    • Understanding imports
    • Python Package Management and Virtual Environments
    • Unit Testing in Python

    • Travaux Pratiques
    • TP: Creating a Linear Regression Package
  • Design Patterns
    • OOP Design Patterns
    • Python-Specific Design Patterns
    • Creation Design Patterns
    • Structural Design Patterns
    • Behavioral Design Pattern

    • Travaux Pratiques
    • TP
  • Sujets de Projets possibles
    • Projets
    • Projets POO - 2024-2025
  • Code source
  1. Structural Design Patterns
  • OOP Design Patterns
  • Python-Specific Design Patterns
  • Creation Design Patterns
  • Structural Design Patterns
  • Behavioral Design Pattern
  • Travaux Pratiques
    • TP

On this page

  • Structural Design Patterns in Python
    • 1. Adapter Pattern
      • 1.1 Example: Legacy Data System Adapter
      • 1.2 Benefits of Adapter
    • 2. Bridge Pattern
      • 2.1 Example: Cross-Platform Shape Drawing
      • 2.2 Benefits of Bridge
    • 3. Composite Pattern
      • 3.1 Example: File System Structure
      • 3.2 Benefits of Composite
    • 4. Decorator Pattern
      • 4.1 Example: Coffee Ordering System
      • 4.2 Benefits of Decorator
    • 5. Facade Pattern
      • 5.1 Example: Home Theater Facade
      • 5.2 Benefits of Facade
    • 6. Flyweight Pattern
      • 6.1 Example: Character Rendering in a Document
      • 6.2 Benefits of Flyweight
    • 7. Proxy Pattern
      • 7.1 Example: Lazy Loading Image Proxy
      • 7.2 Benefits of Proxy
    • Conclusion

Structural Design Patterns

Cours
Fondamentaux
Découvrir les design paterns, et connaitre les plus standards
Author

Remi Genet

Published

2024-10-21

Structural Design Patterns in Python


Structural patterns explain how to assemble objects and classes into larger structures while keeping these structures flexible and efficient.

1. Adapter Pattern

The Adapter pattern allows objects with incompatible interfaces to collaborate.

1.1 Example: Legacy Data System Adapter

1.2 Benefits of Adapter

  • Integrates incompatible interfaces
  • Improves reusability of existing code
  • Enhances flexibility in system design

2. Bridge Pattern

The Bridge pattern separates an object’s abstraction from its implementation, allowing them to vary independently.

2.1 Example: Cross-Platform Shape Drawing

2.2 Benefits of Bridge

  • Decouples abstraction from implementation
  • Improves extensibility
  • Hides implementation details from clients

3. Composite Pattern

The Composite pattern lets you compose objects into tree structures and then work with these structures as if they were individual objects.

3.1 Example: File System Structure

3.2 Benefits of Composite

  • Simplifies client code when working with complex hierarchies
  • Makes it easy to add new types of components
  • Provides flexibility in structuring data

4. Decorator Pattern

The Decorator pattern lets you attach new behaviors to objects by placing these objects inside special wrapper objects that contain the behaviors.

4.1 Example: Coffee Ordering System

4.2 Benefits of Decorator

  • Adds responsibilities to objects dynamically
  • Provides a flexible alternative to subclassing
  • Allows for a mix-and-match approach to adding features

5. Facade Pattern

The Facade pattern provides a simplified interface to a complex subsystem.

5.1 Example: Home Theater Facade

5.2 Benefits of Facade

  • Simplifies interface to a complex subsystem
  • Decouples client code from subsystem
  • Provides a context for usage

6. Flyweight Pattern

The Flyweight pattern lets you fit more objects into the available amount of RAM by sharing common parts of state between multiple objects instead of keeping all of the data in each object.

6.1 Example: Character Rendering in a Document

6.2 Benefits of Flyweight

  • Reduces memory usage when dealing with a large number of similar objects
  • Improves performance in applications with many objects
  • Centralizes state for many virtual objects

7. Proxy Pattern

The Proxy pattern lets you provide a substitute or placeholder for another object. A proxy controls access to the original object, allowing you to perform something either before or after the request gets through to the original object.

7.1 Example: Lazy Loading Image Proxy

7.2 Benefits of Proxy

  • Controls access to the original object
  • Can manage the lifecycle of the original object
  • Adds a level of indirection for distributed, controlled, or intelligent access

Conclusion

Structural design patterns provide various ways to organize code for better structure, flexibility, and efficiency. They help in creating relationships between entities, making systems easier to maintain and extend. By understanding and applying these patterns, developers can create more robust and scalable software architectures.

Back to top
Creation Design Patterns
Behavioral Design Pattern

Programmation Orienté Object en Python, Rémi Genet.
Licence
Code source disponible sur Github

 

Site construit avec et Quarto
Inspiration pour la mise en forme du site ici
Code source disponible sur GitHub