> For the complete documentation index, see [llms.txt](https://ondrej-kvasnovsky-2.gitbook.io/design-patterns-handbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ondrej-kvasnovsky-2.gitbook.io/design-patterns-handbook/master.md).

# Introduction

This handbook is full of examples to inspire usage and easier understanding of design patterns. What actually is a pattern?

*Each pattern is a three-part rule, which expresses a relation between a certain context, a problem, and a solution. -- Alexander*

When we start learning design patterns, we might tend to use them whenever possible. That can lead to over-engineering, which produces more code than it is necessary to implement the needed requirement. It is also called as over using of design patterns.

One way to escape over-engineering is to use Test Driver Development. TDD is made of 3 phases. First, write a simple test. Second, make the test pass, by implementing behavior that is required by the test. Third, refactor what we have coded to make the test pass. The third phase is the ideal place to think about design patterns, because when we want to refactor the code, we have a problem “how to make the code better?”. The design patterns are here to help us with problems, not to be a fancy toys to make our code better.

Always remember, when we use design patterns to solve code problem we face to, the intention is to lower complexity, never increase. That way we only produce low complexity code that is going to be readable and easily maintanable.

Interesting links and reference materials:

* [Examples of GoF Design Patterns in Java's core libraries](https://stackoverflow.com/questions/1673841/examples-of-gof-design-patterns-in-javas-core-libraries)
* [Design patterns deep dive](https://sourcemaking.com/design_patterns) by SourceMaking&#x20;
* Refactoring to Patterns by Joshua Kerievsky


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ondrej-kvasnovsky-2.gitbook.io/design-patterns-handbook/master.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
