当前位置:首页 » 软件开发
开发技术指南» 文章正文
    引言: There is a principle of object-o
 

 

 ·keep changes small: a happy jack story    »显示摘要«
    摘要:jack walked into the office one monday morning. underneath his arm, he carried a rolled-up piece of poster paper. he walked to the back of the building, where a group of couches and tables made up the......
    摘要:at the end of 2004, microsoft will stop supporting windows nt. at that point, anyone using windows nt will have several choices: follow microsofts upgrade path to windows 2003, continue to use windows......


Principles, Patterns, and Practices: The Factory Pattern

there is a principle of object-oriented design known as the dependency inversion principle (dip). this principle tells us that we should try to avoid depending on things that are concrete. for example, given the choice between holding a reference to a list or its derivative linkedlist, we should choose the base class list.

linkedlist balls = new linkedlist();

we should write: 【程序编程相关:关于Map和List的性能测试报告

in other words, rather than writing: 【推荐阅读:用BeanShell实现公式管理

the dip says: "depend on abstractions, not on concretions." this is just another way of expressing the old maxim of information hiding. in this case we are hiding the true type of an object from all of its users. 【扩展信息:设计合适的接口

list balls = new linkedlist();

the reason for this should be obvious. we can pass balls around as a list to any function or object that takes a list argument. later, if we decide to change the definition of balls to an arraylist, we need only change one line of code.

but what about the new statement above? it specifically uses the concrete class linkedlist. this clearly violates the dip. indeed, the statement list balls = new linkedlist(); is quixotic. it tilts at windmills by flagrantly exposing the concrete type of balls and then pretending to hide it.

if we only create the balls list in one place, then at least we can claim to be hiding its type from the rest of the application, even if we do expose it here in one place. however, if we have a function of the form:


...   下一页
    摘要:anyone who has dealt with complex enterprise applications knows the value of a good logging solution. features such as consolidating log files, separating events, and turning debugging on or off all c......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE