zw7534313的博客 -凯发k8国际

`
文章列表
  使用责任链模式进行类型转换   public class test {  public static void main(string[] args) {  date d = new date();  double d2 = new double("99.145456");  string str = null;    formaterchain fc = formaterchain.getinstance();  fc.add(new dateformater());  fc ...
  essage从第一个链开始判断和处理,如果不能处理就传给下一个链,每一个链用handler表示。所有的链继承自同一个父类,handler   使多个对象都有机会处理请求,从而避免请求的 发送者和接受者之间的耦合。将这些对象连成一个链,并按着这个链传递该请求,直到有一个对象处理他为止   public class test {  public static void main(string[] args) {    handler h1 = new buygoodshandler();  handler h2 = new paymoneyhandler();  handler h ...
  /** * 建造者模式:将一个复杂的对象的构建与它的表示分离,使得同样的构建过程可以有不同的表示。 * 建造者模式通常包括以下这几个角色:    1、builder:给出一个抽象接口,规范建造者对于生产的产品的各个组成部分的建造。这个接口只是定一个规范,不涉及具体的建造,具体的建造让继承于它的子类(concretebuilder)去实现。    2、concretebuilder:实现builder接口,针对不同的商业逻辑,具体化各对象部分的建造,最后返回一个建造好的产品。    3、director:导演,顾名思义,负责规范流程之用。在指导中不涉及产品的创建,只负责保证复杂对象各部分被 ...
puremve:1.在页面 close="destroy()"  creationcomplete="init()"2.在init()方法中facade.startup(roleconfignotification.role_config_startup,this);3.在facade中,registercommand(roleconfignotification.role_config_startup, roleconfigcommand); 4.在command 中,facade.registerproxy(new roleconfigproxy(r ...
bridge模式:将抽象和行为划分开来,各自独立,但能动态的结合。   public abstract class coffee{ coffeeimp coffeeimp;  public void setcoffeeimp(){     this.coffeeimp=coffeeimpsingleton.getthecoffeeimp(); } public coffeeimp getcoffeeimp(){    return this.coffeeimp; } public abstract void pourcoffee();}   public abstract class ...
  • 2009-11-16 17:36
  • 浏览 979
adapter模式:     public interface iroundpeg{     public void insertintohole(string msg); }   public interface isquarepeg{ public void insert(string str);}   public class roundpeg implements iroundpeg{  public void insertintohole(string msg) {  system.out.println("roundpeg insertintohole() ...
  • 2009-11-16 16:39
  • 浏览 947
command模式:command模式在界面设计中应用广泛.java的swing中菜单命令都是使用command模式。,调用者基本只和接口打交道,不合具体实现交互,这也体现了一个原则,面向接口编程。     public interface command {     public abstract void execute();}   public class engineer implements command { public void execute( ) { system.out.println("engineer doing............." ...
  • 2009-11-16 15:34
  • 浏览 997
state模式:     public class context {   public static final int state_one = 0;  public static final int state_two = 1;   private state currentstate = new concretestate1();  public void request() {  currentstate.handle();  }   public void changestate(int state) {  switch (state) {  case state_one ...
  • 2009-11-16 14:51
  • 浏览 1124
strategy模式:来对轮胎的样式进行不同的替换,可以替换成短轮胎痕迹的汽车轮胎,这样在不更改car类的前题下进行了不同轮胎样式的改变,轮胎和轮胎之间可以互相替换,这就是策略模式。     public class car {    private luntai ...
  • 2009-11-16 14:28
  • 浏览 946
iterator模式:可以为容器或其子容器实现不同的迭代方法或多个迭代方法。   package com; import java.util.iterator; public class book{ private string bookname; private string author; public string getbookname() {  return bookname; } public void setbookname(string bookname) {  this.bookname = bookname; } public string getauthor() { ...
  • 2009-11-16 12:04
  • 浏览 983
decrator模式:即wrapper模式,其强制控制作用是在不改动一个类的代码或者不破坏一个类的接口的情况下为该类添加功能。当你想一个类具有更多功能的时候,使用decorator模式意味着增加功能后的版本不一定要通过扩展类来重用现有功能。  使用decorator比使用继承产生更少的类,所以其代码比较简单;但是它通常产生更多的对象,将导致调试难度增加,尤其是因为它增加了灵活度,可能会引入新的错误。     public class person { private string name;  public string getname(){  return name; } public ...
  • 2009-11-16 10:42
  • 浏览 1082
observer模式: 具体的说,如果网上商店中商品在名称 价格等方面有变化,如果系统能自动通知会员,将是网上商店区别传统商店的一大特色.这就需要在商品product中加入observer这样角色,以便product细节发生变化时,observer能自动观察到这种变化,并能进行及时的update或notify动作。   java的api还为为我们提供现成的observer接口java.util.observer.我们只要直接使用它就可以. 我们必须extends java.util.observer才能真正使用它:1.提供add/delete observer的方法;2.提供通知(noti ...
  • 2009-11-13 10:24
  • 浏览 1085
facade模式:为子系统中的一组接口提供一个一致的界面.
  • 2009-11-13 09:37
  • 浏览 911
应用factory模式:一个类(接口)有多个子类   1.静态工厂方法你会建立一个专门生产sample实例的工厂: public class factory{   public static sample creator(int which){   //getclass 产生sample 一般可使用动态类装载装入类。  if (which==1)    return new samplea();  else if (which==2)    return new sampleb();   } }   //sample 是父类,samplea,sampleb是子类   2.抽 ...
  • 2009-11-13 09:28
  • 浏览 942
1.在一个extends observable类的类中需要调用this.setchanged();方法, 还得调用this.notifyobservers(arg);可以带参数,也可以不带,会执行实现了observer接口update(observable o,object obj)方法,在这个方法中可以获取arg参数.(一个类的执行会引起另一个类的执行) public class myobservable extends observable { integer i; public void set(integer i){  this.i=i;  this.setchanged(); }  ...
  • 2009-08-20 10:08
  • 浏览 1012
global site tag (gtag.js) - google analytics
网站地图