Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to study design patterns? [closed]

People also ask

How do you practice design patterns?

Two steps: Read 'design patterns' and 'refactoring to patterns' book. Use refactoring katas for practice: identify opportunities to use design patterns, refactor to them and evaluate the result.

How do you read a design pattern?

Design patterns are reusable templates for commonly occurring problems in software design. They are not as straightforward as code snippets that can be directly transferred to the program. Instead, they present a generalized strategy that developers can apply to solve issues when designing software.

What design patterns use the Open Closed Principle and how?

For example, the Decorator pattern offers us to follow the Open Close principle. Furthermore, we may use the Factory Method, Strategy pattern and the Observer pattern to design an application with minimum changes in the existing code. That's all about 'SOLID Principles : The Open Closed Principle'.


I read three books and still did not understand patterns very well until I read Head First Design Patterns by OReilly. This book opened my eyes and really explained well.

alt text


The best way is to begin coding with them. Design patterns are a great concept that are hard to apply from just reading about them. Take some sample implementations that you find online and build up around them.

A great resource is the Data & Object Factory page. They go over the patterns, and give you both conceptual and real world examples. Their reference material is great, too.


My two cents for such and old question

Some people already mentioned, practice and refactoring. I believe the right order to learn about patterns is this:

  1. Learn Test Driven Development (TDD)
  2. Learn refactoring
  3. Learn patterns

Most people ignore 1, many believe they can do 2, and almost everybody goes straight for 3.

For me the key to improve my software skills was learning TDD. It might be a long time of painful and slow coding, but writing your tests first certainly makes you think a lot about your code. If a class needs too much boilerplate or breaks easily you start noticing bad smells quite fast

The main benefit of TDD is that you lose your fear of refactoring your code and force you to write classes that are highly independent and cohesive. Without a good set of tests, it is just too painful to touch something that is not broken. With safety net you will really adventure into drastic changes to your code. That is the moment when you can really start learning from practice.

Now comes the point where you must read books about patterns, and to my opinion, it is a complete waste of time trying too hard. I only understood patterns really well after noticing I did something similar, or I could apply that to existing code. Without the safety tests, or habits of refactoring, I would have waited until a new project. The problem of using patterns in a fresh project is that you do not see how they impact or change a working code. I only understood a software pattern once I refactored my code into one of them, never when I introduced one fresh in my code.


Derek Banas made youtube tutorials for desing patterns that I like a lot:

http://www.youtube.com/playlist?list=PLF206E906175C7E07

They can be a little short in time, but his timing and presentation makes them very enjoyful to learn.