心随所致,梦想为开。Follow the Dreams & Heart.
Posts tagged design patterns
The Decorator Pattern
Mar 15th
Decorator – Attach additional reponsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
CName: Wrap
OO Principles:
- Classes should be open for extension but close for modification.
Bullet Points:
- Inheritance is one form of extension, but not necessarily the best way to achieve flexibility in our designs.
- In our designs we should allow behavior to be extended without the need to modify existing code.
- Compostion and delegation can often be used to add new behaviors at runtime. (more…)
The Observer Pattern
Mar 13th
Observer – defines a ont-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
OO Principles
- Strive for loosely coupled designs between objects that interact.
Bullet Points
- The Observer Pattern defines a ont-to-many relationship between objects.
- Subjects, or we also known them, Observables, update Observers using a common interface.
- Observers are loosely coupled in that the observalbe knows nothing about them, other than that they implement the Observer interface.
- You can push or pull the data of the Observalbe when using the pattern(pull is considered more “correct”).
- Don’t depend on a specific order of notification for you Observers. (more…)
The Strategy Pattern
Mar 9th
The Strategy Pattern defines a family of algorithms, encapsulates each once, and makes them interchangebale. Strategy lets the algorithm vary independently from clients that use it.
OO Principles:
- Encapsulate what varies.
- Favor compostion ove inheritence.
- Program to interface, not implementation.
Bullet Points:
- Knowing the OO basics does not make you a great OO designer.
- Good OO designs are reusable, extensible and maitainable.
- Patterns are proven object-oriented experience.
- Patterns don’t give you code, the give you general solution to design problems. You apply them to your specific application. (more…)
Road to Excellence
Feb 5th
看来语言还是很重要的,其实一直都明白这个道理,不过“行胜于言”这句话还是很有道理的。今天看了几篇别人的故事和一些相关的讨论,这种感觉就更加强烈。
多一门语言,路就宽很多。
Tag: Road to Excellence