Chinaunix首页 | 论坛 | 博客
  • 博客访问: 251584
  • 博文数量: 45
  • 博客积分: 170
  • 博客等级: 入伍新兵
  • 技术积分: 488
  • 用 户 组: 普通用户
  • 注册时间: 2012-09-13 14:43
文章分类

全部博文(45)

文章存档

2014年(2)

2013年(35)

2012年(8)

我的朋友

分类: Java

2013-11-26 16:19:06


点击(此处)折叠或打开

  1. package cn.edu.shou.hsh;

  2. public interface Sender {
  3.     void send();
  4. }


  5. package cn.edu.shou.hsh;

  6. public class MessageSender implements Sender {

  7.     @Override
  8.     public void send() {
  9.         // TODO Auto-generated method stub
  10.         System.out.println("message......");
  11.     }

  12. }


  13. package cn.edu.shou.hsh;

  14. public class MailSender implements Sender {

  15.     @Override
  16.     public void send() {
  17.         // TODO Auto-generated method stub
  18.         System.out.println("mail......");
  19.     }

  20. }


  21. package cn.edu.shou.hsh;

  22. public interface AbstractFactory {
  23.     Sender execute();
  24. }


  25. package cn.edu.shou.hsh;

  26. public class MailFactory implements AbstractFactory {

  27.     @Override
  28.     public Sender execute() {
  29.         // TODO Auto-generated method stub
  30.         return new MailSender();
  31.     }

  32. }


  33. package cn.edu.shou.hsh;

  34. public class MessageFactory implements AbstractFactory {

  35.     @Override
  36.     public Sender execute() {
  37.         // TODO Auto-generated method stub
  38.         return new MessageSender();
  39.     }

  40. }


  41. package cn.edu.shou.hsh;

  42. public class Test {

  43.     /**
  44.      * @author hsh
  45.      * @param args
  46.      */
  47.     public static void main(String[] args) {
  48.         // TODO Auto-generated method stub
  49.         AbstractFactory af=new MessageFactory();
  50.         Sender send=af.execute();
  51.         send.send();
  52.     }

  53. }

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