Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1674870
  • 博文数量: 210
  • 博客积分: 10013
  • 博客等级: 上将
  • 技术积分: 2322
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-25 15:56
文章分类

全部博文(210)

文章存档

2011年(34)

2010年(121)

2009年(37)

2008年(18)

我的朋友

分类: Java

2011-02-25 20:11:52

package hello;

/**
 * 原型模式
 * @author HZ20232
 *
 */

public class ProtocolPattern{
    public static void main(String args[]){
        ColoneProtocol p1 = new ColoneProtocol("HelloWorld!");
        Protocol p2 = (Protocol)p1.Clone();
        System.out.println(p1.getName()+"****"+p2.getName());
    }
}
class Protocol implements Cloneable{
    private String name;
    public void setName(String n){
        this.name = n;
    }
    public String getName(){
        return this.name;
    }
    public Object Clone(){
        try{
            return super.clone();
        }catch(Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
class ColoneProtocol extends Protocol{
    public ColoneProtocol(String n){
        super.setName(n);
    }
}


阅读(901) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2011-03-06 16:54:40

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com

chinaunix网友2011-03-06 16:54:05

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com