Skip to content

Commit 13275f8

Browse files
committed
2 parents fb2d7f8 + e940092 commit 13275f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1049
-12
lines changed

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,30 @@ You will learn these Design Patterns
3535
* Template
3636
* Visitor
3737

38-
<!--
39-
Register for the course at Skillshare. https://skl.sh/34SM2Xg **(Get Extra 2 Months Premium Membership Free)**
40-
-->
38+
39+
Register for the course at
40+
- [Skillshare](https://skl.sh/34SM2Xg) **(Get Extra 2 Months Premium Membership Free)**
41+
- [Udemy](https://www.udemy.com/course/design-patterns-in-python/?referralCode=7493DBBBF97FF2B0D24D) **(New Student Discount)**
42+
4143

4244
## Introduction Video
4345

4446
[![Design Patterns in Python Introduction](https://img.youtube.com/vi/OOxyTUWsY7A/0.jpg)](https://youtu.be/OOxyTUWsY7A)
4547

4648

47-
<!--
48-
To register for this course visit
4949

50-
<a href="https://skl.sh/34SM2Xg" target="_blank"><img src="https://github.com/img/skillshare_btn.png" title="Skillshare 2 Months Free Premium Membership"/></a>
50+
To register for this course visit
5151

52-
<b>
53-
* Get 2 Months Free Premium Membership to 1000s of Courses <br>
54-
* Full Lifetime Access <br/>
55-
* Subscription Model <br/>
56-
* Cancel Any Time</b>
57-
-->
52+
<a href="https://skl.sh/34SM2Xg" target="_blank"><img src="img/skillshare_btn.png" title="Skillshare 2 Months Free Premium Membership"/></a>
5853

54+
- Get 2 Months Free Premium Membership to 1000s of Courses
55+
- Full Lifetime Access
56+
- Subscription Model
57+
- Cancel Any Time
5958

59+
<a href="https://www.udemy.com/course/design-patterns-in-python/?referralCode=7493DBBBF97FF2B0D24D" target="_blank"><img src="img/udemy_btn.png" title="Udemy Design Patterns in Python"/></a>
6060

61+
- One Time Payment
62+
- Full Lifetime Access
63+
- Certificate of Completion
64+
- 30 Day Money-Back Guarantee

docs/CNAME

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
designpatterns.seanwasere.com

docs/abstract_factory.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Abstract Factory Design Pattern
2+
3+
The Abstract Factory Pattern adds an abstract layer over multiple factory method implementations.
4+
5+
The Abstract Factory contains or composites one or more than one factory method
6+
7+
![Abstract Factory Overview](abstract_factory.png)
8+
9+
Abstract Factory in the context of a Furniture factory
10+
![Abstract Factory in context](abstract_factory_furniture.png)
11+
12+
13+
Import existing factories
14+
```python
15+
from chair_factory import ChairFactory
16+
from table_factory import TableFactory
17+
```
18+
19+
Create an interface
20+
```python
21+
class IFurnitureFactory(metaclass=ABCMeta):
22+
"""Furniture Factory Interface"""
23+
24+
@abstractstaticmethod
25+
def get_furniture(furniture):
26+
"""The static funiture factory interface method"""
27+
```
28+
29+
The factories abstract static method which delegates to the correct factory
30+
```python
31+
32+
class FurnitureFactory(IFurnitureFactory):
33+
"""The Furniture Factory Concrete Class"""
34+
35+
@staticmethod
36+
def get_furniture(furniture):
37+
"""Static get_furniture method"""
38+
try:
39+
if furniture in ["SmallChair", "MediumChair", "BigChair"]:
40+
return ChairFactory().get_chair(furniture)
41+
if furniture in ["SmallTable", "MediumTable", "BigTable"]:
42+
return TableFactory().get_table(furniture)
43+
raise AssertionError("No Furniture Factory Found")
44+
except AssertionError as _e:
45+
print(_e)
46+
return None
47+
```
48+
49+
50+
Requesting from the abstract factory at run time
51+
```python
52+
if __name__ == "__main__":
53+
FURNITURE = FurnitureFactory.get_furniture("SmallChair")
54+
print(f"{FURNITURE.__class__} : {FURNITURE.dimensions()}")
55+
56+
FURNITURE = FurnitureFactory.get_furniture("MediumTable")
57+
print(f"{FURNITURE.__class__} : {FURNITURE.dimensions()}")
58+
```

docs/abstract_factory.png

16 KB
Loading
70.2 KB
Loading

docs/adapter.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Adapter Design Pattern
2+
3+
The adapter design pattern solves these problems:
4+
5+
- How can a class be reused that does not have an interface that a client requires?
6+
- How can classes that have incompatible interfaces work together?
7+
- How can an alternative interface be provided for a class?
8+
9+
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.
10+
11+
So we need to create an adapter, that wraps the incompatible object, but implements the standardised interface.
12+
13+
## Two Incompatible Classes
14+
![Adapter Design Pattern](adapter_before.png)
15+
16+
## After Creating an Adapter
17+
![Adapter Design Pattern](adapter.png)

docs/adapter.png

10.9 KB
Loading

docs/adapter_before.png

5.56 KB
Loading

docs/atm.png

20.5 KB
Loading

docs/builder.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Builder Design Pattern
2+
3+
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.
4+
5+
The Builder Pattern tries to solve,
6+
- How can a class create different representations of a complex object?
7+
- How can a class that includes creating a complex object be simplified?
8+
9+
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.
10+
11+
Parts of the Builder Pattern
12+
1. **Product** - The Product being built
13+
2. **Concrete Builder** - Build the concrete product. Implements the IBuilder interface
14+
3. **Builder Interface** - The Interface which the Concrete builder should implement
15+
4. **Director** - Has a construct method which when called creates a customised product
16+
17+
![Builder Pattern Overview](builder.png)
18+
19+
The Builder Pattern in the context of a House Builder. There are multiple directors creating there own complex objects
20+
21+
![Builder Pattern in Context](house_builder.png).

0 commit comments

Comments
 (0)