/design-patterns-in-python

Just refreshing some design patterns and learning some advanced python on the way.

Primary LanguagePython

Design Patterns in Python

Just refreshing some design patterns and learning some python along the way.

Behavioral Patterns

Behavioral design patterns are concerned with algorithms and the assignment of responsibilities between objects.

  • Observer Pattern: lets you define a subscription mechanism to notify multiple objects about any events that happen to the object they’re observing.
  • Strategy Pattern: lets you define a family of algorithms, put each of them into a separate class, and make their objects interchangeable.
  • Iterator Pattern: lets you traverse elements of a collection without exposing its underlying representation (list, stack, tree, etc.).
  • Memento Pattern: lets you save and restore the previous state of an object without revealing the details of its implementation.

Structural Patterns

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

  • Decorator Pattern: lets you attach new behaviors to objects by placing these objects inside special wrapper objects that contain the behaviors.
  • Composite Pattern: lets you compose objects into tree structures and then work with these structures as if they were individual objects.

Creational Patterns

Creational design patterns provide various object creation mechanisms, which increase flexibility and reuse of existing code.

  • Builder: lets you construct complex objects step by step. The pattern allows you to produce different types and representations of an object using the same construction code.

Sources