Builder Design Pattern
Videos
| Section | Video Links |
|---|---|
| Builder Overview | ![]() |
| Builder Use Case | ![]() |
| Python List | ![]() |
Book
Overview
... Refer to Book, pause Video Lectures or subscribe to Medium Membership to read textual content.
Terminology
... Refer to Book, pause Video Lectures or subscribe to Medium Membership to read textual content.
Builder UML Diagram
Source Code
... Refer to Book, pause Video Lectures or subscribe to Medium Membership to read textual content.
Output
python ./builder/builder_concept.py ['a', 'b', 'c']
Example Use Case
... Refer to Book, pause Video Lectures or subscribe to Medium Membership to read textual content.
Example UML Diagram
Output
python ./builder/client.py This is a Ice Igloo with 1 door(s) and 0 window(s). This is a Sandstone Castle with 100 door(s) and 200 window(s). This is a Wood House Boat with 6 door(s) and 8 window(s).
New Coding Concepts
Python List
In the file /builder/builder_concept.py
def __init__(self): self.parts = []
The [] is indicating a Python List.
The list can store multiple items, they can be changed, they can have items added and removed, can be re-ordered, can be pre-filled with items when instantiated and is also very flexible.
PS> python >>> items = [] >>> items.append("shouldn't've") >>> items.append("y'aint") >>> items.extend(["whomst", "superfluity"]) >>> items ["shouldn't've", "y'aint", 'whomst', 'superfluity'] >>> items.reverse() >>> items ['superfluity', 'whomst', "y'aint", "shouldn't've"] >>> items.remove("y'aint") >>> items ['superfluity', 'whomst', "shouldn't've"] >>> items.insert(1, "phoque") >>> items ['superfluity', 'phoque', 'whomst', "shouldn't've"] >>> items.append("whomst") >>> items.count("whomst") 2 >>> len(items) 5 >>> items[2] = "bagnose" >>> items ['superfluity', 'phoque', 'bagnose', "shouldn't've", 'whomst'] >>> items[-2] "shouldn't've"
Lists are used in almost every code example in this book. You will see all the many ways they can be used.
In fact, a list was used in the /abstract_factory/furniture_factory.py example,
if furniture in ['SmallChair', 'MediumChair', 'BigChair']: ...
This line, creates a list at runtime including the strings 'SmallChair', 'MediumChair' and 'BigChair'. If the value in furniture equals the same string as one of those items in the list, then the condition is true and the code within the if statement block will execute.
Summary
... Refer to Book, pause Video Lectures or subscribe to Medium Membership to read textual content.



