/**
- @Author: cxh
- @CreateTime: 18/1/25 22:45
- @ProjectName: JavaBaseTest
*/
public class BrandA1 extends PhoneBrand {
@Override
public void run() {
super.softWare.run();
}
}
/**
- @Author: cxh
- @CreateTime: 18/1/25 22:47
- @ProjectName: JavaBaseTest
*/
public class BrandA2 extends PhoneBrand {
@Override
public void run() {
super.softWare.run();
}
}
/**
- @Author: cxh
- @CreateTime: 18/1/25 22:46
- @ProjectName: JavaBaseTest
*/
public class BrandB1 extends PhoneBrand {
@Override
public void run() {
super.softWare.run();
}
}
/**
-
@Author: cxh
-
@CreateTime: 18/1/25 22:51
-
@ProjectName: JavaBaseTest
-
测试类
*/
public class Client {
public static void main(String[] args) {
PhoneBrand brand;
//手机品牌A1
System.out.println("----手机品牌A1----");
brand=new BrandA1();
brand.setSoftWare(new SoftWareV1());
brand.run();
brand.setSoftWare(new SoftWareV2());
brand.run();
brand.setSoftWare(new SoftWareV3());
brand.run();
//手机品牌A2
System.out.println("----手机品牌A2----");
brand=new BrandA2();
brand.setSoftWare(new SoftWareV1());
brand.run();
brand.setSoftWare(new SoftWareV2());
brand.run();
brand.setSoftWare(new SoftWareV3());
brand.run();
//手机品牌A3
System.out.println("----手机品牌A3----");
brand=new BrandB1();
brand.setSoftWare(new SoftWareV1());
brand.run();
brand.setSoftWare(new SoftWareV2());
brand.run();
brand.setSoftWare(new SoftWareV3());
brand.run();
}
}
/**
-
@Author: cxh
-
@CreateTime: 18/1/25 22:40
-
@ProjectName: JavaBaseTest
*/
public abstract class PhoneBrand {
//持有软件的引用
protected PhoneSoftWare softWare;
public void setSoftWare(PhoneSoftWare softWare) {
this.softWare = softWare;
}
//调用软件功能方法
public abstract void run();
}
/**
- @Author: cxh
- @CreateTime: 18/1/25 22:39
- @ProjectName: JavaBaseTest
*/
public abstract class PhoneSoftWare {
abstract void run();
}
/**
- @Author: cxh
- @CreateTime: 18/1/25 22:48
- @ProjectName: JavaBaseTest
*/
public class SoftWareV1 extends PhoneSoftWare {
@Override
void run() {
System.out.println("手机通信录功能运行");
}
}
/**
- @Author: cxh
- @CreateTime: 18/1/25 22:49
- @ProjectName: JavaBaseTest
*/
public class SoftWareV2 extends PhoneSoftWare{
@Override
void run() {
System.out.println("手机游戏功能运行");
}
}
/**
- @Author: cxh
- @CreateTime: 18/1/25 22:50
- @ProjectName: JavaBaseTest
*/
public class SoftWareV3 extends PhoneSoftWare {
@Override
void run() {
System.out.println("手机拍照功能运行");
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。