码迷,mamicode.com
首页 > 其他好文 > 详细

适配器模式

时间:2014-08-23 19:00:51      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   os   io   for   ar   art   

bubuko.com,布布扣

Taget

 1 package com.learning.designpattern.adapter;
 2 
 3 public class Target {
 4     
 5     public void operation(){
 6         System.out.println("target operation");
 7     }
 8     
 9 
10 }

Adaptee

1 package com.learning.designpattern.adapter;
2 
3 public class Adaptee {
4 
5     public void request(){
6         System.out.println("real request");
7     }
8 }

Adapter

 1 package com.learning.designpattern.adapter;
 2 
 3 public class Adapter extends Target {
 4     
 5     private Adaptee adaptee;
 6     
 7     @Override
 8     public void operation() {
 9         if(adaptee==null){
10             adaptee = new Adaptee();
11         }
12         adaptee.request();
13 
14     }
15 
16 
17 }

Client:

 1 package com.learning.designpattern.adapter;
 2 
 3 public class Client {
 4 
 5     /**
 6      * @param args
 7      */
 8     public static void main(String[] args) {
 9         Target target = new Adapter();
10         target.operation();
11 
12     }
13 
14 }

 

适配器模式

标签:des   style   blog   color   os   io   for   ar   art   

原文地址:http://www.cnblogs.com/ryanwangblog/p/3931573.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!