


/**
- @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("手机拍照功能运行");
}
}
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|