装饰者模式(例子)
2016-01-01 13:22
405 查看
MiPhone
iPhone
3、创建抽象装饰类Decorator,包含一个MobilePhone类型的私有变量。
Bluetooth
GPS
Camera
5、书写主函数Main来分别创建小米手机和苹果手机,并且分别加上蓝牙功能、GPS功能和视频通话功能。
输出结果看是否符合要求:
iPhone
3、创建抽象装饰类Decorator,包含一个MobilePhone类型的私有变量。
Bluetooth
GPS
Camera
5、书写主函数Main来分别创建小米手机和苹果手机,并且分别加上蓝牙功能、GPS功能和视频通话功能。
1 public class Main { 2 3 public static void main(String[] args) { 4 // TODO Auto-generated method stub 5 MiPhone miPhone=new MiPhone(); 6 iPhone iphone=new iPhone(); 7 8 Bluetooth miBluetooth=new Bluetooth(miPhone); 9 miBluetooth.Connect(); 10 GPS miGPS=new GPS(miPhone); 11 miGPS.Location="MiPhone的定位成功"; 12 System.out.println(miGPS.Location); 13 Camera miCamera=new Camera(miPhone); 14 miCamera.VideoCall(); 15 16 Bluetooth iBluetooth=new Bluetooth(iphone); 17 iBluetooth.Connect(); 18 GPS iGPS=new GPS(iphone); 19 miGPS.Location="iPhone的定位成功"; 20 System.out.println(miGPS.Location); 21 Camera iCamera=new Camera(iphone); 22 iCamera.VideoCall(); 23 } 24 25 }
输出结果看是否符合要求:
相关文章推荐
- 近似计算
- MySQL binlog格式解析
- The requested URL /Users/add was not found on this server.
- 十进制转任意进制(正数)
- win7输入法全角/半角切换热键该怎么修改?
- 【Java数据结构】链表
- ajax技术的简单练习题
- LeetCode Median of Two Sorted Arrays
- poj3169Layout【差分约束】
- python 中列表、元组、字典、文件的区别
- Android开发之 Android应用程序目录结构解析
- Intellij IDEA Android Studios 修改包名
- copy的使用...NSStringFromClass([string class])... NSTaggedPointerString
- 数据库架构的演变
- 自定义AngularJS中的services服务
- eclipse修改字体
- CPC广告反作弊
- Paint---PathEffect(路径效果)
- 创建选项菜单OptionsMenu
- 分享一个分页类。