ITeye博客

2012 年文章归档

共 9 篇文章

六大设计原则总结:6)开闭原则 -Open Closed Principle

Open Closed Principle: Software entities like classes, modules and functions should be open for extension but closed for modifications. **对扩展开放,对修改关闭。**一个软件实体应该通过扩展来实现变化,而不是通过修改已有代码来实现变化。 一个软件实体应该通过扩展来实现 变化 ,而不是通过修改已有的代码来实现变化。——but,并不意味着不做任何修改;底层模块的扩展,必然要有高层模块进行耦合。 变化可分为三种类型: 逻辑变化——不涉及其他模块,可修改原有类中的…

2012-12-31 16:14

六大设计原则总结:5)迪米特法则 -Law of Demeter

LoD,Law of Demeter: 又称最少知识原则(Least Knowledge Principle),一个对象应该对其他对象有最少的了解 一个类对自己依赖的类知道的越少越好。也就是说,对于被依赖的类来说,无论逻辑多么复杂,都尽量地的将逻辑封装在类的内部,对外除了提供的public方法,不对外泄漏任何信息。 问题由来: 类与类之间的关系越密切,耦合度越大,当一个类发生改变时,对另一个类的影响也越大。 解决方案: 迪米特法则包含4层含义: 1)只和朋友交流 Only talk to your immediate friends.两个对象之间的耦合就成为 朋友 关系。即,出现在成员变量、…

2012-12-31 16:13

六大设计原则总结:4)接口隔离原则 -Interface Segregation Principle

Interface Segregation Principle: Clients should not be forced to depend upon interfaces that they don't use.——客户端只依赖于它所需要的接口;它需要什么接口就提供什么接口,把不需要的接口剔除掉。 The dependency of one class to another one should depend on the smallest possible interface.——类间的依赖关系应建立在最小的接口上。 即, 接口尽量细化 ,接口中的方法尽量少 问题由来: 类A通过接口I…

2012-12-31 16:12

六大设计原则总结:3)依赖倒置原则 -Dependence Inversion Principle:

DIP,Dependence Inversion Principle: High level modules should not depend upon low level modules. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions. 即“面向接口编程”: 高层模块不应该依赖低层模块,两者都应该依赖其抽象;——模块间的依赖通过抽象发生。实现类之间不发生直接的依赖关系(eg. 类B被用作类A…

2012-12-31 16:10

六大设计原则总结:2)里氏替换原则 -Liskov Substitution Principle

LSP,Liskov Substitution Principle: 1) If for each object s of type S , there is an object t of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when s is substituted for t when S is a subtype of T . 2) Functions that use pointers or references to base classe…

2012-12-31 16:08

六大设计原则总结:1)单一职责原则 -Single Responsibility Principle

SRP,Single Responsibility Principle: There should never be more than one reason for a class to change. 应该有且仅有一个原因引起类的变更。(如果类需要变更,那么只可能仅由某 一个 原因引起) 问题由来: 类T负责两个不同的职责:职责P1,职责P2。当由于职责P1需求发生改变而需要修改类T时,有可能会导致原本运行正常的职责P2功能发生故障。 解决方案: 遵循单一职责原则。分别建立两个类T1、T2,使T1完成职责P1功能,T2完成职责P2功能。这样,当修改类T1时,不会使职责P2发生故障风险;同…

2012-12-29 16:31

Service Data Objects(SDO) 简介

SDO是为了屏蔽数据格式、数据源的差异性而出现的。新公司用到了SDO并自己做了SDO的实现,作为学习,试着翻译这篇篇IBM 2004年的文章 原文:http://www.ibm.com/developerworks/java/library/j-sdo 摘要: 如果你觉得J2EE编程模型及其API总是让你在特定技术配置(technology-specific configuration)、编码、调试上花费太多时间,那么这篇文章就对你有用!许多Java程序员疑惑怎样用统一的方式访问异构数据,并对许多打算解决这个问题的编程框架很失望。Bertrand Portier 和Frank Budinsk…

2012-12-28 17:44

自动创建Excel sheet页索引的办法

方法一: 1)先下载一个Excel文件: http://vdisk.weibo.com/s/lKO2s 2)把Catalog页移动到需要建立索引的Excel文件中 3)右键Create按钮 - Assign Macro... - 选择:Catalog.Create_DropDown_MainMenu 右键Clear按钮 - Assign Macro... - 选择:Catalog.DeleteSpecifyShapes 4)点击Create即可生成目录: 方法二: 首先打开要创建目录的EXCEL文件 —— Alt+F11——插入——模块——把下面的代码拷贝到模块中: 然后Tools - Ma…

2012-12-27 17:40

Hibernate.update()、merge()及引申

http://www.hibernate-training-guide.com/merge.html update()方法存在的问题: In session, Hibernate guarantees no two Persistent objects represent the same row. Again, this guarantee no longer holds with Detatched objects. In fact, this problem can create very unwanted consequences. Explore the code below. H…

2012-12-27 11:05