For writing efficient and maintainable code, there are few principles that a programmer should keep in mind, these would become second nature with time. These design principles give way to more concrete and refined implementation for solving specific use cases called design patterns. A must to build reliable system that are also easy to maintain.
I am listing down some of these principle here:
I am listing down some of these principle here:
- Identify the aspects of your code that vary and separate them from what stays the same.
"Encapsulate what varies"
If some aspect of the code is changing, that's a sign you should pull it out and separate it.
By separating out the parts of your code that vary, you can extend or
alter them
without affecting the rest of the code.
without affecting the rest of the code.
- Program to an interface, not an implementation.
- Favour composition over inheritance.
- Strive for loosely coupled designs between objects that interact.
- Classes should be open for extension but closed for modification (The open-closed principle)
- A class should have only one reason to change.
These were from one of the lectures by Eric Freeman, the author of Head First Design Patterns. I would recommend checking out the book for detailed take on design pattern or one of his courses on software design or programming..
No comments:
Post a Comment