Reference: o1-mini —> real world example

❗️It’s been a while since I wrote this blog, and it needs an update. The key changes I plan to make are: (1) Expanding on Decorator and Iterator patterns, (2) Updating the code with real-world examples


I wrote this blog to understand Design Patterns in Python and why we need them My interest in design patterns didn't begin with the goal of writing cleaner or more optimised code (naive me). Instead, I was studying Language Model (LM) agents and discovered how proper design and architecture could enhance even basic LMs with capabilities like reasoning (ReAct) and calculation (which LMs typically struggle with). This led me to implement various agents like ReAct and Reflect from scratch using AWS Sagemaker Endpoint, without relying on any wrappers.

I came to appreciate the beauty and of various patterns on reading source code of libraries like PyTorch, HuggingFace, and llama-index. Yet I was wondering why people would complicate code only to make it elegant. I read on it and found this standard answer:

Software design patterns are general, reusable solutions to common problems that arise during the design and development of software.

While this answer was accurate, I still wondered why specific patterns like Abstract Factory and Decorator exist. After reading numerous articles. I came to realise

<aside> 💡

Patterns exist to often addressing specific limitations or "deficiencies" within programming languages. And patterns like Factory, Singleton, and Observer are prevalent in languages such as Java and C++ to mitigate their particular constraints. While Python has unique features and characteristics, it also necessitate certain patterns to overcome its own set of challenges like

</aside>

The ones I found relevant are


Concepts from OOPS