KEMBAR78
Python: Common Design Patterns | PPTX
Common Design Patterns
Damian Gordon
Common Design Patterns
• Iterator
• Decorator
• Observer
• Strategy
• State
• Singleton
• Template
• Adapter
• Façade
• Flyweight
• Command
• Abstract Factory
• Composite
Iterator Pattern
• The iterator pattern is a design pattern in which an iterator is
used to traverse a container and access the container's
elements.
Decorator
Decorator Pattern
• The decorator pattern is a design pattern which wraps an
existing class and can alter the functionality of the methods.
Existing Class
Observer Pattern
• The observer pattern is a design pattern which monitors a core
class and different observers react different to changes in the
core class.
Existing Class
Observer 1
Observer 2
Strategy Pattern
• The strategy pattern is a design pattern which presents
different potential solutions to the same problem, and allows
the program to choose the most suitable one.
Solution 1 Solution 3Solution 2
Abstraction
State Pattern
• The state pattern is a design pattern which represents a system
that goes through different states, and records the current
state and the transitions between states.
State 1 State 3State 2
Current
State
Manager
(or Context)
Singleton Pattern
• The singleton pattern is a design pattern which allows only one
object based on a certain class to exist.
One Object
Template Pattern
• The template pattern is a design pattern which creates a
common base class the can be inherited by multiple class that
share common states, these can override the base class
methods. Base Case:
Step1()
Step2()
Step3()
Case1:
Step2()
Case2:
Step3()
Adapter Pattern
• The adapter pattern is a design pattern which allows two pre-
existing objects to interact with each other, even if their
interfaces are not compatible.
Interface 1 Interface2
Adapter
Façade Pattern
• The façade pattern is a design pattern which presents a simple
interface to complex system but encapsulating typical usage
into a new object.
Façade
BIG
SYSTEM
Flyweight Pattern
• The flyweight pattern is a design pattern which helps objects
that share the same state to use the same memory location.
Flyweight
Current
State
Command Pattern
• The command pattern is a design pattern which creates an
object (an execute object) that can execute another object at a
later time.
Existing ClassRun 2 hours from now
Execute
Object
Abstract Factory Pattern
• The abstract factory pattern is a design pattern which returns a
different class (or implementation) of the same system,
depending on the platform, local settings, or current locale.
Solution 1 Solution 3Solution 2
Abstract Factory
Composite Pattern
• The composite pattern is a design pattern which allows
complex tree-like structures to be built easily from simple
components.
Composite
Composite
CompositeCompositeLeaf
CompositeLeaf
LeafLeaf
Leaf
etc.

Python: Common Design Patterns

  • 1.
  • 2.
    Common Design Patterns •Iterator • Decorator • Observer • Strategy • State • Singleton • Template • Adapter • Façade • Flyweight • Command • Abstract Factory • Composite
  • 3.
    Iterator Pattern • Theiterator pattern is a design pattern in which an iterator is used to traverse a container and access the container's elements.
  • 4.
    Decorator Decorator Pattern • Thedecorator pattern is a design pattern which wraps an existing class and can alter the functionality of the methods. Existing Class
  • 5.
    Observer Pattern • Theobserver pattern is a design pattern which monitors a core class and different observers react different to changes in the core class. Existing Class Observer 1 Observer 2
  • 6.
    Strategy Pattern • Thestrategy pattern is a design pattern which presents different potential solutions to the same problem, and allows the program to choose the most suitable one. Solution 1 Solution 3Solution 2 Abstraction
  • 7.
    State Pattern • Thestate pattern is a design pattern which represents a system that goes through different states, and records the current state and the transitions between states. State 1 State 3State 2 Current State Manager (or Context)
  • 8.
    Singleton Pattern • Thesingleton pattern is a design pattern which allows only one object based on a certain class to exist. One Object
  • 9.
    Template Pattern • Thetemplate pattern is a design pattern which creates a common base class the can be inherited by multiple class that share common states, these can override the base class methods. Base Case: Step1() Step2() Step3() Case1: Step2() Case2: Step3()
  • 10.
    Adapter Pattern • Theadapter pattern is a design pattern which allows two pre- existing objects to interact with each other, even if their interfaces are not compatible. Interface 1 Interface2 Adapter
  • 11.
    Façade Pattern • Thefaçade pattern is a design pattern which presents a simple interface to complex system but encapsulating typical usage into a new object. Façade BIG SYSTEM
  • 12.
    Flyweight Pattern • Theflyweight pattern is a design pattern which helps objects that share the same state to use the same memory location. Flyweight Current State
  • 13.
    Command Pattern • Thecommand pattern is a design pattern which creates an object (an execute object) that can execute another object at a later time. Existing ClassRun 2 hours from now Execute Object
  • 14.
    Abstract Factory Pattern •The abstract factory pattern is a design pattern which returns a different class (or implementation) of the same system, depending on the platform, local settings, or current locale. Solution 1 Solution 3Solution 2 Abstract Factory
  • 15.
    Composite Pattern • Thecomposite pattern is a design pattern which allows complex tree-like structures to be built easily from simple components. Composite Composite CompositeCompositeLeaf CompositeLeaf LeafLeaf Leaf
  • 16.