banq,其实咱俩的爱好挺一致的。我也是特喜欢写框架,特有成就感。呵呵。
也最讨厌别人写出一些不遵循接口编程原则,结构僵化的代码。
不过,我最近正在一个自我的转变阶段。逐渐有点认识到凡事不能无限制地追求完美。架构的灵活性也总是有限的。
逐渐理解了这个“适当的假设”的必要性。
实际编程中,我也更注意do one thing well。就是说,一个功能,能不做就不做,要做,就做好它。
框架不怕功能有限,怕的是太复杂,怕的是不容易扩展。一个功能,当暂时想不到一个完美的解决办法,我会优先选择放弃它,宁可保持simple and stupid。要知道,加东西比删改对一个框架来说更容易。
至于说设计,呵呵,我这么说可能不大合适。我觉得追求design pattern实在是一个最错误的事情。
时常看到程序员们在讨论“这是pattern A还是pattern B?”,“pattern C的定义是这样的吗?”
让我感叹程序员大好的青春时光就被浪费在模式考据学的泥潭里。
不是说设计不重要。但是,设计不是这么个学法。
design pattern这本书就象围棋的定式书。如果你能够理解这些pattern试图解决的问题,那么把它当作best practice来开阔一下思路很好。但是初学者去直接背诵这些定式招法是有害无益。搞些似是而非的比喻来试图“加深理解”,也只是让人产生一种“我好像理解了”的假想,一样是南辕北辙。
其实,只要你按照接口编程的原则,最小化接口,最小化assumption,自然就会得到良好的设计,你管他是叫肥猪模式还是波若波萝密模式?
就象那个ioc,我都很惊讶会有人给这个东西起出五花八门的名字来。
我比较欣赏这位老兄的这段话,说出了我的心声:
The principles behind what is now being called IoC have been described in many papers over the last 20 years or so, under names such as configuration programming, third-party binding, or architecture description. The idea is to make explicit the relationships between components/objects, instead of code that creates those relationships being hidden within object implementations. (Note: the term Inversion of Control is usually used somewhat differently to the way that the IoC folks are using it.) If you actually design your program using OO principles -- as a set of objects that talk to each other and have no other, hidden interdependencies -- it is very rare NOT to end up with an "IoC" architecture. The fact that so many people think that IoC is some exciting new insight is an indication of the poor quality of OO design that the industry puts up with.
其实,不只ioc,那么多pattern,不都是按照OO原则对某种特定情况设计出来的自然结果吗?何必搞成这么深奥的样子?
全文在这里:
http://www.enterprisej2me.com/blog/java/?postid=12