❓ What are design patterns?

Design patterns emerged (roughly) 30 years ago.

And yet, many people believe they are as relevant today as they've always been.

A thread 🧵 about design patterns. 👇
❓ First, what is "design"?

This thread is about software design, not UI design.

Everything in the code is design. From details such as variable names to more architectural issues.

🔑 Design is the shape that the system takes to meet its requirements.
📔 A design pattern:

🔹 Describes a design solution to a problem that occurs repeatedly.

🔹 Describes the elements (e.g. objects) that make up the solution and their relationships.

🔹 Explains the trade-offs of using the pattern.

🔹Captures experience of skilled designers.
There are others, but you can find the most famous patterns in the book:

➡️ "Design Patterns: Elements of Reusable Object-Oriented Software" [GoF book].

Examples: facade, adapter, command, ...

❓ What are the main advantages of design patterns?

Let's talk about 4 of them. 👇
1⃣ They give us vocabulary to talk about design.

In a team familiar with patterns, design discussions become very productive.

Can you imagine an architect that doesn't use "room patterns" such as bedroom or kitchen?

Patterns allow you to pack a lot of info in short sentences.
2⃣ Design patterns can be seen as examples that show good design principles in action.

For instance, the "State" pattern shows how the "Open-Closed Principle" makes the addition of new states easier.

📔 If you study design patterns, you will gain invaluable design knowledge.
3⃣ Design patterns can give us refactoring targets.

We must avoid overengineering and follow the rules of simple design, refactoring continuously.

When a pattern solves a *real* problem that we have, then we can use the pattern as a guide in the refactoring process.
4⃣ Design patterns can improve the readability of your code.

If the patterns are obvious in our code (that is, if the code *evokes* the patterns, whether using the pattern names or not), then the readers that know the patterns will easily understand our intent.
You can follow @macerub.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: