高聚合,低偶合
为了降低对象之间的耦合度、增加灵活性,于是有了设计模式
设计师们不断地寻求一种复杂度更低的
对struts的优化,定义接口如下:
//ResultSet to Bean
public void ConvertRStoBean(Connection con,ResultSet rs,Map para,_RootBean goal);
或
public void ConvertRStoBean(Connection con,String sql,Map para,_RootBean goal);
//ResultSet to List
public ArrayList ConvertRStoList(Connection con,String sql,Map para,String className);
基本模块设计原则:
1,高聚合:一模块与其他模块之间没有过多的相互作用
2,规模适中:单个模块的成本与系统总成本成反比
3,上下层模块的低耦合:上下层模块之间的影响关联度以及扇入扇出原则
MVC设计原则
M重点在于高内聚和低偶合
C提倡灵活性,定义框架,讲究重用性
目前我对优秀框架的判断标准是:对需求变化的快速构架能力
面向接口和面向切面
面向接口:它是比abstract更抽象的概念,关心的不是具体实现而是更强的扩充性和偶合度,一个设计方法你甚至找不到它的具体实现,这是面向接口的一个境界。
面向切面(AOP):对于非核心且烦琐的业务(如日志,事物等等),为了讲究重用性,把这些片面业务的实现抽象为一个模块,从而省去了大量繁杂的工作,让开发者专注与核心业务的开发。
另外,引入了IOC思想,即对象的周期和对象之间的关系统一由另一容器来构件和管理,并可实现“动态绑定”。
23种设计模式:
看了 cbf4life大哥的写的设计模式,挺生动的。在这里写下我的简要理解。
1,策略模式(Strategy Pattern)
策略接口------>N多策略实现
执行者------->调用策略接口,并不关心用何种策略,可以有某种“选择机制”,组合关系
2,代理模式(Proxy Pattern)
实现者------->做自己该做的实现
代理人------->只接客,但不执行,给相应实现者,在外人看来,是代理者在执行,其实它只是一个“空壳”。
(注意代理人和实现者需同一个interface(问题)),组合关系。
执行者------->调用代理人为自己办事
3,单例模式
4,多例模式 这两个就不说了
5,工厂模式(Factory Pattern)
一个工厂-------用于生产对象实例
产品实现-------各种需要生产的产品
产品类别-------各类产品接口
执行者 --------通知工厂我需要什么产品,并提供规格说明书(这里有种方法可以由已知的interface找到所有实现class)
6,抽象工厂模式(Abstract Facotry Pattern)
一个工厂--------用于生产对象实例
多个部门--------为了适应复杂的对象构造结构,可能产品有方的,或者圆的(抽象类还是实现类,看具体应用)
A类产品实现-----属于A类的产品所有产品(可能定义为abstract class,class)
A类产品接口-----A类产品接口
B类产品实现-----属于A类的产品所有产品(同上)
B类产品接口-----A类产品接口
......
执行者----------调用工厂,提供规格说明书(说明书里标明产品说明,工厂根据说明内容自动匹配叫哪个部门生产,所以单例+参数能解决这个缺点)
7,门面模式(Facade Pattern)
实现者----------这个家伙很累,需要实现A,B,C,D....并不强调执行顺序
实现者接口------实现类的接口
守门人-----------这个人告诉实现者要做事了,做完后把结果告诉他,守门人叫实现者实现
执行着-----------告诉守门人该做事,并告诉守门人这件事为谁而做
组合关系
8,适配器模式(Adapter Pattern)
A类接口---------A类,注意Adapter是适用于不同接口中共用问题的,可能涉及到两个不同子类系统的大类系统中。
B类接口---------B类
一个适配器-------主要作用是把A类接口伪装成B类接口,在B类系统中当作B类对象来操作就OK了。
不符合原有设计的时候才考虑通过适配器模式减少代码修改带来的风险。
9,装饰模式(Decorator Pattern)
原始接口——————
装饰接口——————
装饰实现——————构造函数传递基类对象,这里是组合关系
装饰模式解决“灵活性差”和“主体类在多方向上的扩展问题”,组合关系,对继承关系的补充,可动态地指定扩展功能。
Son son =new AASon();
son =new AADecorator(son);
son =new BBDecorator(son);
son同时具有了AAD BBD两个扩展功能。
10、命令模式(Command Pattern)
做事接口——————
做事者——————A,B,C....
总头头————————定义了很多做事着
头头————————A类人的头,B类人的头,C类人的头...
对客户的接口—————接收要谁做事
客户—————————定义谁做事,给接口
组合关系
附录:
根据完整类名创建对象
public class CJMethods {
public static void main(String args[]) {
try {
Class c = Class.forName(args[0]);
Method m[] = c.getDeclaredMethods();
Field[] fieldArray=className.getDeclaredFields();
for (int i = 0; i < m.length; i++)
System.out.println(m.toString());
} catch (Throwable e) {
System.err.println(e);
}
}
}
分享到:
相关推荐
Model predictive control (MPC) has a long history in the field of control en- gineering. It is one of the few areas that has received on-going interest from researchers in both the industrial and ...
商业模式画布作者的博士毕业论文
Model Predictive Control:Theory, Computation, and Design,2nd Edition. James B. Rawlings, David Q. Mayne, Moritz M. Diehl. Chapter 1 is introductory. It is intended for graduate students in engineering...
Model predictive control (MPC) has a long history in the field of control engineering. It is one of the few areas that has received on-going interest from researchers in both the industrial and ...
An interpretation of MOS modeling for the analog designer, motivated by the EKV MOS model, using tabulated hand expressions and figures that give performance and tradeoffs for the design choices of ...
Go Design Patterns will provide readers with a reference point to software design patterns and CSP concurrency design patterns to help them build applications in a more idiomatic, robust, and ...
Immerse yourself in the fundamentals of mobile game design. This book is written by two highly experienced industry professionals to give real insights and valuable advice on creating games for this ...
Sudoku is a game with incremental intelligence and is popularizing in many countries ...squares, and the mathematical model and statistical method of data from a Sudoku square design, are presented here
The recursive least square (RLS) algorithm is used to identify time-varying parameters in characteristic model. The position controller is constituted by an adaptive equivalent controller based on ...
Using Model-Based Design to Develop SOA Applications for In-Vehicle OS
course in Model Checking. If a reader can verify that he or she has read and studied every article, then Springer should certainly award that reader a Master’s Degree inModel Checking! Departments in...
Meet the building blocks of solid Windows 8 UI design in a well-designed sample app. Learn how to incorporate key design elements into your apps, such as the app bar, charms and subtle animations from...
Frequency Effects 49 as a Function of Current 51 3.6.1 f T ...in the Transistor Model 55 3.10 Bipolar Transistor Design Considerations 56 3.11 CMOS Transistors 57 3.11.1 NMOS 58 ...
DOM Scripting: Web Design with JavaScript and the Document Object Model gives you everything you need to start using JavaScript and the Document Object Model to enhance your web pages with client-...
the necessity of a cost model to compare such alternatives, different mechanisms to traverse and enumerate the search space, and practical aspects in real-world tuning tools. In the third part, the ...
In our previous work we presented a model-based approach to perform robust, high-speed face localization based on the Hausdor® distance. A crucial step during the design of the system is the choice ...
Formulating a domain vision statement * Distilling the core of a complex domain * Digging out implicit concepts needed in the model * Applying analysis patterns * Relating design patterns to the model...
Also, if the design contains an error, model checking will produce a counterexample that can be used to pinpoint the source of the error. The method, which was awarded the 1998 ACM Paris Kanellakis ...