Design Patterns in Python
- Descrição
- Currículo
- FAQ
- Revisões
Course Overview
This course provides a comprehensive overview of Design Patterns in Python from a practical perspective. This course in particular covers patterns with the use of:
-
The latest versions of the Python programming language
-
Use of modern programming approaches: dependency injection, reactive programming and more
-
Use of modern developer tools such as JetBrains PyCharm
-
Discussions of pattern variations and alternative approaches
This course provides an overview of all the Gang of Four (GoF) design patterns as outlined in their seminal book, together with modern-day variations, adjustments, discussions of intrinsic use of patterns in the language.
What are Design Patterns?
Design Patterns are reusable solutions to common programming problems. They were popularized with the 1994 book Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, John Vlissides, Ralph Johnson and Richard Helm (who are commonly known as a Gang of Four, hence the GoF acronym).
The original book was written using C++ and Smalltalk as examples, but since then, design patterns have been adapted to every programming language imaginable: C#, Java, Python and even programming languages that aren’t strictly object-oriented, such as JavaScript.
The appeal of design patterns is immortal: we see them in libraries, some of them are intrinsic in programming languages, and you probably use them on a daily basis even if you don’t realize they are there.
What Patterns Does This Course Cover?
This course covers all the GoF design patterns. In fact, here’s the full list of what is covered:
-
SOLID Design Principles: Single Responsibility Principle, Open-Closed Principle, Liskov Substitution Principle, Interface Segregation Principle and Dependency Inversion Principle
-
Creational Design Patterns: Builder, Factories (Factory Method and Abstract Factory), Prototype and Singleton
-
Structrural Design Patterns: Adapter, Bridge, Composite, Decorator, Façade, Flyweight and Proxy
-
Behavioral Design Patterns: Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method and Visitor
Who Is the Course For?
This course is for Python developers who want to see not just textbook examples of design patterns, but also the different variations and tricks that can be applied to implement design patterns in a modern way. For example, the use of decorators and metaclasses allows us to prepackage certain patterns for easy re-use.
Presentation Style
This course is presented as a (very large) series of live demonstrations being done in JetBrains PyCharm and presented using the Kinetica rendering engine. Kinetica removes the visual clutter of the IDE, making you focus on code, which is rendered perfectly, whether you are watching the course on a big screen or a mobile phone.
Most demos are single-file, so you can download the file attached to the lesson and run it in PyCharm, IDLE or another IDE of your choice.
This course does not use UML class diagrams; all of demos are done via live coding.
-
2OverviewVídeo Aula
What are SOLID principles, where do they come from and why do we care?
-
3Single Responsibility PrincipleVídeo Aula
A look at the Single Responsibility Principle, which states that a class should only have one reason to change. Also tied to the concept of Separation of Concerns which is basically stating the same thing.
-
4Open-Closed PrincipleVídeo Aula
A discussion of the Open-Closed Principle, which states that classes should be open for extension, but closed for modification. In other words, you should extend functionality using interfaces and inheritance rather than jumping back into already-written/tested code and adding to it or changing it.
-
5Liskov Substitution PrincipleVídeo Aula
The Liskov Substitution Principle states that subtypes should be substitutable for their base types.
-
6Interface Segregation PrincipleVídeo Aula
The Interface Segregation Principle is simple: don't throw everything in the kitchen sink into an interface because then all its users will have to implement things they do not need. Instead, split the interface into several smaller ones.
-
7Dependency Inversion PrincipleVídeo Aula
Not to be confused with dependency injection, dependency inversion specifies that high-level modules should not depend on low-level ones; both should depend on abstractions. Confusing, huh?
-
8SummaryVídeo Aula
A summary of the things we've learned in this section of the course.
-
9Gamma CategorizationVídeo Aula
A brief note about the three categories of design patterns: creational, structural and behavioral.
-
10OverviewVídeo Aula
An overview of the Builder design pattern.
-
11BuilderVídeo Aula
An overview of the Builder design pattern.
-
12Builder FacetsVídeo Aula
A look at how several builders can work together through a common fluent interface.
Addendum: there's a small mistake in the PersonBuilder initializer; instead of =Person() it should read =None, see the attached source code for the updated example.
-
13Builder InheritanceVídeo Aula
How to combine the functionality of several builders without breaking OCP.
-
14Builder Coding ExerciseQuestionário
-
15SummaryVídeo Aula
A summary of the things we've learned about the Builder design pattern.
-
16OverviewVídeo Aula
An overview of the Factory design pattern.
-
17Factory MethodVídeo Aula
A constructor is a rather limited tool. A factory method adds flexibility.
-
18FactoryVídeo Aula
A factory is a separate class for creating objects.
-
19Abstract FactoryVídeo Aula
If you have a hierarchy of objects, you can have a corresponding hierarchy of factories.
-
20Factory Coding ExerciseQuestionário
-
21SummaryVídeo Aula
A summary of the things we've learned about the Factory design pattern.
-
22OverviewVídeo Aula
An overview of the Prototype design pattern.
-
23PrototypeVídeo Aula
Learn about deep copying and the Prototype pattern.
-
24Prototype FactoryVídeo Aula
Well known prototypes can be put into a factory for additional convenience.
-
25Prototype Coding ExerciseQuestionário
-
26SummaryVídeo Aula
A summary of all the things we've learned about the Prototype design pattern.
-
27OverviewVídeo Aula
An overview of the much-maligned Singleton design pattern.
-
28Singleton AllocatorVídeo Aula
You can make an allocator that keeps returning the same object. Trouble is, the initializer still gets called more than once!
-
29Singleton DecoratorVídeo Aula
Let's implement the Singleton as a decorator!
Note: if you don't know how Python decorators work, see the Decorator pattern lectures.
-
30Singleton MetaclassVídeo Aula
Let's implement the Singleton using a metaclass!
-
31MonostateVídeo Aula
A peculiar variation on the 'canonical' singleton, Monostate objects all share the same static dictionary.
-
32Singleton TestabilityVídeo Aula
Why is the Singleton problematic? What can we do to fix it?
-
33Singleton Coding ExerciseQuestionário
-
34SummaryVídeo Aula
A summary of the things we've learned about the Singleton design pattern.
-
35OverviewVídeo Aula
An overview of the Adapter design pattern.
-
36Adapter (no caching)Vídeo Aula
Let's implement the adapter pattern — perhaps not in the most efficient manner.
-
37Adapter (with caching)Vídeo Aula
Let's improve our Adapter implementation with some caching!
-
38Adapter Coding ExerciseQuestionário
-
39SummaryVídeo Aula
A summary of what we've learned about the Adapter design pattern.
-
44OverviewVídeo Aula
An overview of the Composite design pattern.
Note: for more information on iteration, please consult the Iterator pattern lectures.
-
45Geometric ShapesVídeo Aula
First, a simple example: grouping geometric shapes.
-
46Neural NetworksVídeo Aula
Implementing connections between neurons and neuron layers with the Composite pattern.
-
47Composite Coding ExerciseQuestionário
-
48SummaryVídeo Aula
A summary of the things we've learned about the Composite design pattern.
-
49OverviewVídeo Aula
An overview of the Decorator design pattern.
-
50Python Functional DecoratorsVídeo Aula
To some extent, the Decorator pattern is built right into the Python language. Let's take a look at how Python's functional decorators work.
-
51Classic DecoratorVídeo Aula
A classic GoF decorator is a class that gives additional functionality to the underlying class. The only problem is the original class' attributes are now inaccessible.
-
52Dynamic DecoratorVídeo Aula
A dynamic decorator lets us treat the decorator as if it were the object it decorates. This works for purposes of ordinary programming, but won't work with any sort of metaprogramming.
-
53Decorator Coding ExerciseQuestionário
-
54SummaryVídeo Aula
A summary of the things we've learned about the Decorator design pattern.
-
59OverviewVídeo Aula
An overview of the Flyweight design pattern.
-
60User NamesVídeo Aula
Many online games store actual user names. But is it worth storing every first-last name pair individually?
-
61Text FormattingVídeo Aula
We want to apply formatting to plain text. What's the most memory-efficient way of doing this?
-
62Flyweight Coding ExerciseQuestionário
-
63SummaryVídeo Aula
A summary of the things we've learned about the Flyweight design pattern.
-
64OverviewVídeo Aula
An overview of the Proxy design pattern.
-
65Protection ProxyVídeo Aula
A protection proxy can be used to add access control to a resource.
-
66Virtual ProxyVídeo Aula
A virtual proxy can masquerade as a real object even when the object has not yet been materialized.
-
67Proxy vs DecoratorVídeo Aula
Proxy and Decorator look like similar patterns. So what's the difference?
-
68Proxy Coding ExerciseQuestionário
-
69SummaryVídeo Aula
A summary of the things we've learned about the Proxy design patterns.
-
70OverviewVídeo Aula
An overview of the Chain of Responsibility design pattern.
-
71Method ChainVídeo Aula
A chain of responsibility implemented as a linked list of function references.
-
72Command Query SeparationVídeo Aula
Our next example uses queries, so now is a good time to mention CQS, another concept closely related to design patterns.
-
73Broker ChainVídeo Aula
A more sophisticated Chain of Responsibility implementation! An event broker is a centralized component that can process queries by letting all subscribers handle and possibly modify them.
-
74Chain of Responsibility Coding ExerciseQuestionário
-
75SummaryVídeo Aula
A summary of the things we've learned about the Chain of Responsibility design pattern.
-
76OverviewVídeo Aula
An overview of the Command design pattern.
-
77CommandVídeo Aula
Let's implement the Command design pattern and also support Undo operations.
-
78Composite CommandVídeo Aula
A Composite Command (a.k.a. a Macro) is a merger of the Composite and Command design patterns. Let's see how they play together.
-
79Command Coding ExerciseQuestionário
-
80SummaryVídeo Aula
A summary of the things we've learned about the Command design pattern.
