-
2004-10-20
performance
Network Connection |
Remote Network Call |
Local Network Call |
Local Call |
-
2004-10-14
《敏捷软件开发:原则、模式与实践》中文版序
“最好的软件开发人员都知道一个秘密:美的东西比丑的东西创建起来更廉价,也更快捷。构建、维护一个美的软件系统所花费的时间、金钱都要少于丑的系统。软件开发新手往往不理解这一点。他们认为做每件事情都必须要快,他们认为美是不实用的。错!由于事情做得过快,他们造成的混乱致使软件僵化,难以理解。美的系统是灵活、易于理解的,构建、维护它们就是一种快乐。丑陋的系统才是不实用的。丑陋会降低你的开发速度,使你的软件昂贵而又脆弱。构建、维护美的系统所花费的代价最少,交付起来也最快。”
----摘自“Robert C. Martin《敏捷软件开发:原则、模式与实践》中文版序”
Robert C. Martin《敏捷软件开发:原则、模式与实践》中文版序
除了我的家庭,软件是我的挚爱。通过它,我可以创造出美的东西。软件之美在于它的功能,在于它的内部结构,还在于团队创建它的过程。对用户来说,通过直观、简单的界面呈现出恰当特性的程序就是美的。对软件设计者来说,被简单、直观地分割,并具有最小内部耦合的内部结构就是美的。对开发人员和管理者来说,每周都会取得重大进展,并且生产出无缺陷代码的具有活力的团队就是美的。美存在于所有这些层次之中,它们都是本书内容的一部分。
软件开发人员如何学到创造美的知识呢?在本书中,我讲授了一些原则、模式以及实践,它们可以帮助软件开发人员在追求美的程序、设计以及团队的道路上迈出第一步。其中,我们探索了基本的设计原则,软件设计结构的通用模式以及有助于团队融为一个有机整体的一系列实践。由于本书是关于软件开发的,所以包含了许多代码。仔细研究这些代码是学习本书所教授的原则、模式以及实践的最有效方法。
人们需要软件--需要许多的软件。50年前,软件还只是运行在少量大型、昂贵的机器之上。30年前,软件可以运行在大多数公司和工业环境之中。现在,移动电话、手表、电器、汽车、玩具以及工具中都运行有软件,并且对更新、更好软件的需求永远不会停止。随着人类文明的发展和壮大,随着发展中国家不断构建它们的基础设施,随着发达国家努力追求更高的效率,就需要越来越多的软件。如果在所有这些软件之中,都没有美存在,这将会是一个很大的遗憾。
我们知道软件可能会是丑陋的。我们知道软件可能会难以使用、不可靠并且是粗制滥造的;我们知道有一些软件系统,其混乱、粗糙的内部结构使得对它们的更改既昂贵又困难;我们还见过那些通过笨拙、难以使用的界面展现其特性的软件系统;我们同样也见过那些易崩溃且行为不当的软件系统。这些都是丑陋的系统。糟糕的是,作为一种职业,软件开发人员所创建出来的美的东西却往往少于丑的东西。如果你正在阅读这本书,那么你也许就是那个想去创造美而不是丑的人。
最好的软件开发人员都知道一个秘密:美的东西比丑的东西创建起来更廉价,也更快捷。构建、维护一个美的软件系统所花费的时间、金钱都要少于丑的系统。软件开发新手往往不理解这一点。他们认为做每件事情都必须要快,他们认为美是不实用的。错!由于事情做得过快,他们造成的混乱致使软件僵化,难以理解。美的系统是灵活、易于理解的,构建、维护它们就是一种快乐。丑陋的系统才是不实用的。丑陋会降低你的开发速度,使你的软件昂贵而又脆弱。构建、维护美的系统所花费的代价最少,交付起来也最快。
我希望你能喜爱这本书。我希望你能像我一样学着以创建美的软件而骄傲,并享受其中的快乐。如果你从本书中略微看到了这种快乐,如果本书使你开始感受到了这种骄傲,如果本书点燃了你内心欣赏这种美的火花,那么就远超过我的目标了。
-
2004-10-11
Create a object through two options
One is to create a object with a rich constructor so that its at least created with all
least created with all its mandatory data.
The other is to create o object an empty object and then populate it with the mandatory
data.
The former could have a well-formed object from the start.This aslo meants that, if you
have an immutable field, you can enforce it by not providing any method to change its
value.
The problem with a rich constructor is that you have to be aware of cyclic references.
Avoiding this requires special case code, often usingg lazy load.
You can do this creating an empty object.Use a non-arg constructor to create a blank object
and insert that empty object immediately into other object.The way,if you have a cycle,
other object will return an object to stop the recursive loading that two objects reference
each other.
Using an empty object like this means you may need some setters for values that are truely
immutalbe when the object is loaded.A combination of a naming convention and perhaps some
status-checking guards can fix this.You can alse use reflection for loading data.(Spring supports Setter Injection very nice.Sometimes using rich constructor to create a object
is preferable after you evaluating.) -
2004-10-11
修改Eclipse Workspace路径
eclipse的worspace的路径放置在根目录:
\configuration\org.eclipse.ui.ide\recentWorkspaces.xml
eg:
-
2004-09-29
How close my Statement
在O/R Mapper的代码中,Statement的关闭模式:
clearup的实现:
/**
* Close database resource.
*
* @param conn
* @param pstmt
*/
protected void clearup(Connection conn, PreparedStatement pstmt)
{
if (pstmt != null)
{
try
{
pstmt.close();
}
catch (SQLException se)
{
se.printStackTrace();
}
pstmt = null;
}
if (conn != null)
{
try
{
conn.close();
}
catch (SQLException se)
{
se.printStackTrace();
}
conn = null;
}
}
1.一般模式
Connection conn = null;
PreparedStatement pstmt = null;
try
{
conn = getConnection();
pstmt = conn.prepareStatement(SQL);
pstmt.setString(1, id);
pstmt.setString(2, type);
pstmt.executeUpdate();
} catch (SQLException se)
{
throw new ApplicationException(se);
} finally
{
clearup(conn, pstmt);//有效的close了Connection;只有一个pstmt,相当于只打开了一个光标,在这里有效的close了pstmt.
}
1.在使用jdbc进行批处理的时候,注意每一次创建一个Statement,一旦无须使用,立刻关闭,因为每一次都是打开了Oracle的一个cursor.(Oracle默认最大一次打开300个,最多也
只支持1000多个)
Connection conn = null;
PreparedStatement pstmt = null;
try
{
conn = getConnection();
pstmt = conn.prepareStatement(SQL1);
pstmt.setString(1, id);
pstmt.setString(2, type);
pstmt.executeUpdate();
pstmt.close(); // 请立刻close当前pstmt的光标。
pstmt = null; // 必须使用
pstmt = conn.propareStatement(SQL2);
pstmt.setString(1, id);
pstmt.setString(2, type);
pstmt.executeUpdate();
pstmt.close(); // 请立刻close当前pstmt的光标。
pstmt = null; // 必须使用
… …
} catch (SQLException se)
{
throw new ApplicationException(se);
} finally
{
clearup(conn, pstmt); //有效的close了Connection;只有出现exception才能有效close pstmt;
}









