Design Patterns in Python
4.2 (9 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
48 students enrolled

Design Patterns in Python

Learn and Discover Common GOF (Gang Of Four) Design Principles implemented in Python.
4.2 (9 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
48 students enrolled
Created by Sean Bradley
Last updated 7/2020
English
Current price: $12.99 Original price: $199.99 Discount: 94% off
30-Day Money-Back Guarantee
This course includes
  • 2 hours on-demand video
  • 10 downloadable resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
Training 5 or more people?

Get your team access to 4,000+ top Udemy courses anytime, anywhere.

Try Udemy for Business
What you'll learn
  • Design Patterns in Python
  • Common GOF Design Principles
  • Quality Software Design Standards
  • A Common Software Engineering Vocabulary
Course content
Expand all 15 lectures 02:13:42
+ Creational Design Patterns
4 lectures 36:29

Factory Design Pattern

The Factory Pattern is a creational pattern that defines an Interface for creating an object and defers instantiation until runtime.

Used when you don't know how many or what type of objects will be needed until or during runtime.

Preview 09:41

Abstract Factory Design Pattern

The Abstract Factory Pattern adds an abstract layer over multiple factory method implementations.

The Abstract Factory contains or composites one or more than one factory method.

Preview 09:26

Builder Design Pattern

The Builder Pattern is a creational pattern whose intent is to separate the construction of a complex object from its representation so that you can use the same construction process to create different representations.

The Builder Pattern tries to solve,

  • How can a class create different representations of a complex object?

  • How can a class that includes creating a complex object be simplified?

The Builder and Factory patterns are very similar in the fact they both instantiate new objects at run time. The difference is when the process of creating the object is more complex, so rather than the Factory returning a new instance of ObjectA, it could call the builders director construct method ObjectA.construct(). Both return an Object.

Parts of the Builder Pattern

  1. Product - The Product being built

  2. Concrete Builder - Build the concrete product. Implements the IBuilder interface

  3. Builder Interface - The Interface which the Concrete builder should implement

  4. Director - Has a construct method which when called creates a customised product

Builder
07:56

Prototype Design Pattern

Prototype design pattern is good for when creating a new objects may require more resources than you want to use or have available, versus just making a new copy in memory. Eg, A file you've downloaded from a server may be large, but since it is already in memory, you could just clone it, and work on the new copy independently of the original.

In the prototype patterns interface, you create a static clone method that should be implemented by all classes that use the interface. How the clone method is implemented in the concrete class is up to you. You will need to decide whether a shallow or deep copy is required.

  • A shallow copy, copies and creates new references 1 level deep,

  • A deep copy, copies and creates new references for all levels.

In Python you have mutable objects such as Lists, Dictionaries, Sets and any custom Objects you have created. A shallow copy, will create new copies of the objects with new references in memory, but the underlying data will point to the same location as the original copy. Be sure to test your implementation that the copy method you use works as you expect.

Prototype
09:26
+ Behavioural Design Patterns
6 lectures 01:12:08

Command Design Pattern

The command pattern is a behavioural design pattern, in which an abstraction exists between an object that invokes a command, and the object that performs it.

The components if the Command Design Pattern are,

  1. Receiver - The Object that will receive and execute the command

  2. Invoker - Which will send the command to the receiver

  3. Command Object - Itself, which implements an execute, or action method, and contains all required information to execute it

  4. Client - The application or component which is aware of the Receiver, Invoker and Commands

Eg, a button, will call the Invoker, which will call a pre registered Commands execute method, which the Receiver will perform.

A Concrete Class will delegate a request to a command object, instead of implementing the request directly. Using a command design pattern allows you to separate concerns a little easier and to solve problems of the concerns independently of each of the layers. eg, logging the execution of a command and it's outcome.

Uses: GUI Buttons, menus Macro recording Multi level undo/redo networking - send whole command objects across a network, even as a batch parallel processing or thread pools, transactional behaviour Wizards

Notes: The receiver object should manages it's own state, not the command object There can be one or more invokers which can execute the command at a later date.

Preview 16:29

This is a continuation of the Command Design Pattern, but implementing a Undo/Redo functionality.

Command with Undo/Redo
28:35

Chain of Responsibility Design Pattern

Chain of responsibility pattern is a behavioural pattern used to achieve loose coupling in software design. In this example, a request from a client is passed to a chain of objects to process them. The objects in the chain will decide how to process them and/or pass them to the next in the chain. The objects can also modify the next in the chain if for example you wanted to run objects in a recursive manner.

Chain of Responsibility
07:07

Observer Pattern

The observer pattern is a software design pattern in which an object, called the subject or observable, manages a list of dependents, called observers, and notifies them automatically of any internal state changes, and calls one of their methods.

Observer
07:42

An interface with next and has_next methods.


next returns the next object in the aggregate(collection, list)


has_next returns a value, usually a boolean indicating if the iterable is at the end of the list or not.


The benefits of using the Iterator pattern is that the client, can traverse an aggregate without needing to understand it's internal representation and data structures.



Iterator
05:25

The mediator pattern is a behavioural pattern that defines an object that encapsulates how a set of objects interact.

With the mediator pattern, communication between objects is encapsulated within a mediator object.

Objects communicate through the mediator rather than directly with each other.

Mediator
06:50
+ Structural Design Patterns
5 lectures 25:05

Adapter Design Pattern

The adapter design pattern solves these problems:

  • How can a class be reused that does not have an interface that a client requires?

  • How can classes that have incompatible interfaces work together?

  • How can an alternative interface be provided for a class?

In this lecture, I have 2 classes, they don't share the same interface. The client requires it's objects to use an already standardised interface.

So we need to create an adapter, that wraps the incompatible object, but implements the standardised interface.

Adapter
06:06

Decorator Design Pattern

The decorator pattern is a structural pattern, that allows you to attach additional responsibilities to an object at run time.

The decorator pattern is used in both the Object Oriented and Functional paradigms.

The decorator pattern is different than the Python language feature of Python Decorators in it's syntax, but the application of it is the same, in the way that it is essentially a wrapper.

The Decorator pattern adds extensibility, without modifying the original function.

Decorator
04:01

Façade Design Pattern

The Façade Pattern is a structural design pattern. It provides a simplified interface to a set of other interfaces, abstractions and implementations within a system that may be full of complexity and/or tightly coupled.

Facade
04:25

The Composite design pattern,

  • allows you to represent individual entities and groups of entities in the same manner.

  • is a structural design pattern that lets you compose objects into a tree.

  • is great if you need the option of swapping hierarchal relationships around. 

  • makes it easier for you to add new kinds of components

  • provides flexibility of structure

  • conform to the Single Responsibility Principle in the way that it separates the aggregation of objects from the features of the object.

Examples of using the Composite Design Pattern can be seen in a filesystem directory structure, where you can swap the hierarchy of folders, and in a drawing program where you can group, un-group and transform objects, and multiple objects at the same time.

Composite
06:09

The proxy design pattern is a class functioning as an interface to another class or object.

A proxy could be for anything, such as a network connection, an object in memory, a file, or anything else you need to provide an abstraction between.

It is a wrapper called by a client to access the real underlying object.

Additional functionality can be provided at in the proxy abstraction if required. eg, 

  • caching

  • authorization

  • validation

  • lazy initialization

  • logging

  • security

The proxy should implement the subject interface as much as practicable so that the proxy and subject appear identical to the client.

The Proxy Pattern may occasionally also be referred to as Monkey Patching or Object Augmentation.

Proxy
04:24
Requirements
  • Basic Knowledge of Python 3
  • An OS such as Windows 10, Mac OSX or Linux
  • An IDE such as Visual Studio Code, PyCharm Community, Vim or Just the command line.
Description

This course is about common GOF (Gang Of Four) Design Patterns implemented in Python.

A Design Pattern is a description or template that can be repeatedly applied to a commonly recurring problem in software design.
You will find a familiarity with Design Patterns very useful when planning, discussing, developing, managing and documenting your applications from now on and into the future.

You will learn these Design Patterns

  • Creational

    • Factory

    • Abstract Factory

    • Builder

    • Prototype

  • Behavioural

    • Command

    • Command - Undo/Redo

    • Chain of Responsibility

    • Observer

    • Iterator

    • Mediator

  • Structural

    • Adapter

    • Decorator

    • Façade

    • Composite

    • Proxy


There are many downloadable resources attached to this course. I demonstrate and discuss all the code examples throughout the video lectures.

Thanks for joining my course on Design Patterns in Python.

Who this course is for:
  • Python Developers
  • Software Architects
  • Software Engineers