I recently read 3 books on design patterns, Head first design patterns,learning Javascript design Patterns, and the way to pick up a few years of English.
We all know an old question: what are the benefits of object-oriented? Reusable, scalable, easy to maintain, flexible. I write a program in an object-oriented language (such as C #), and my code certainly doesn't automatically get the above benefits, depending on how I write it. How to write reusable, extensible, maintainable and flexible code, Daniel has already summed up the following design principles:
- Seperate what changes from what stays the same
- Program to a interface, not an implementation
- Favor composition over inheritance
- Strive for loosely coupled designs between objects that interact
- Classes should is open for extension, but close to modification
- Talk your immediate friends
- A class should has only one reason to change
If you only use a word to summarize the design principles, then it must be the first one, package changes. After all, change is "enemy", it is unavoidable, it drives us to burn the brain to accumulate strong code to pit it.
For this reason, Daniel has given us a "weapon", a variety of design patterns, to solve some aspect of a particular type of problem or problem. Design pattern is not a specific solution, it is more like a recognized template, we use this template to solve the problem. In the face of different situations, choose the right design mode, and appropriate use, decided the good or bad, is my current goal:)
The sequence of JS design pattern