public void add(IPhone iPhone) {
listPhone.add(iPhone);
}
@Override
public void sendUpdateMsg() {
for (IPhone iphone : listPhone) {
iphone.update();
}
}
}
package com.oop.demo5;
import java.util.ArrayList;
import java.util.List;
/**
- 戴尔服务器对象
- @author Liudeli
*/
public class DELLService extends Service {
private List listPhone = new ArrayList();
@Override
public void add(IPhone iPhone) {
listPhone.add(iPhone);
}
@Override
public void sendUpdateMsg() {
for (IPhone iphone : listPhone) {
iphone.update();
}
}
}
package com.oop.demo5;
/**
- 更新手机的规范
- @author Liudeli
*/
public interface IPhone {
/**
- 更新所有手机的行为标准规范
*/
public void update();
}
package com.oop.demo5;
/**
- 魅族手机对象
- @author Liudeli
*/
public class MeizuPhone implements IPhone {
public void update() {
System.out.println(“魅族手机需要去更新QQ了哦…”);
}
}
package com.oop.demo5;
/**
- 小米手机对象
- @author Liudeli
*/
public class MIPhone implements IPhone {
public void update() {
System.out.println(“小米手机更新QQ了…”);
}
}
package com.oop.demo5;
/**
- 三星手机对象
- @author Liudeli
*/
public class SamsungPhone implements IPhone {
public void update() {
System.out.println(“三星手机该更新QQ啦…”);
}
}
package com.oop.demo5;
/**
- 步步高手机对象
- @author Liudeli
*/
public class VivoPhone implements IPhone {
public void update() {
System.out.println(“步步高手机需要去更新手机QQ了哦…”);
}
}
/**
- 测试端程序
- @author Liudeli
*/
public class Main {
public static void main(String[] args) {
// 使用戴尔服务器,来更新手机QQ
Ser