--- title: Design Patterns --- ## Design Patterns Programmers and software architects use design patterns to solve **common, recurring problems** in software architecture. The patterns provide a language-agnostic approach to **object-oriented programming** that helps developers follow principles of good application design. ### Why Design Patterns? Developing by design patterns offer several advantages: * It's easier to follow good programming principles such as the **SOLID principles.** * It keeps code chunks smaller so code is easier to **test** and **debug** * It helps keep code loosely coupled so code is easier to **re-use** and **update** for new applications * It makes code easier to **understand**, so new contributors can **ramp up quickly** Using design patterns incurs some trade-offs, and developers new to the practice should remember the following: * There are **no silver bullets** in programming, and design patterns are not an exception * Design patterns add a **layer of abstraction** to code which increases initial design and development effort * Over-use of design patterns or forcing them to fit makes code **harder** to understand ### Language Support Design patterns originated from the world of statically-typed languages like C++, Java, and C#. Most resources about development by design pattern are based in one of these languages. Nonetheless, design patterns are just that: patterns. They are **not implementations**, like classes or interfaces, and are **not constrained to any one language**. When learning design patterns within a dynamic language, if particular patterns seem needlessly complex or counter-intuitive, recall their origins. Developers in dynamic languages can still use and benefit from following design patterns, although more research may be required to fully understand them. ### Uses Design patterns are excellent at solving foundational coding problems in a simple and repeatable fashion. Broadly, they fall into three categories: * **Creational** patterns describe how to create new objects * **Structural** patterns describe how to compose objects out of other objects * **Behavioral** patterns describe how objects communicate with each other These tasks can all be performed without design patterns, but design patterns **reduce the risk** that you will violate good practices and create code that is hard to maintain. #### More Information: * Kamran Ahmed's Design Patterns for Humans is an excellent introduction to the specific patterns * Design Patterns is the book that started this practice * Martin Fowler's Patterns of Enterprise Application Architecture provide a suite of more sophisticated patterns for enterprise applications * Sourcemaking provides an online resource with additional examples and information about design patterns