总结一下最近看设计模式的收获

来源:互联网 发布:seo有哪些优势 编辑:程序博客网 时间:2024/04/27 17:24

最近看了strategy, observer, factory method, abstract factory, decorator, command, singleton, adaptor, facade这些模式,加上原来听的一些模式,可以说大概对设计模式有了个概念。总的说来我觉得设计模式的初衷就是提高维护的重用性,尽量使得客户代码不需要改变。在我看的这些模式中,除了facade之外,基本上都是一个抽象类持有另一个抽象类(接口)的引用,然后在这个抽象基类中调用这个饮用的方法。由于所持有的都是抽象类(接口)的引用,所以很用以借由多态来达到目的。这些类(接口)之间的耦合关系都很松散,因为他们都不知道对方是怎么实现的,依赖抽象而不是实现就有这个好处。

 
设计模式并不是很复杂,但是掌握确实不易,其实自己做的过程中也会有意无意的用到设计模式,或者是programming idioms。其实idioms离patterns的距离很近,或者也可以说很远,抽象的高度还是不在一个级别上。
 
嗯~~最近看得感觉也就这些吧,再写下重要的几点来提醒自己:
1 favor composition to inheritance
2 encapsulate what varies
3 depend on abstract not implementation
4 keep easy and stupid
5 never use inheritance only in sake of code reuse
6 maintainance resuable is always more important than code
7 one class one goal
 
K, that's it, I'll complete this remainder later when I got more
 

原创粉丝点击