黑马程序员技术交流社区
标题:
定制服务设计模式的问题
[打印本页]
作者:
jonn
时间:
2013-1-15 19:08
标题:
定制服务设计模式的问题
interface InternetService{
public void connect();
public void disconnect();
}
interface MailService{
public void send();
public void receive();
}
interface VirusService{
public void begin();
public void end();
}
class InternetServiceImpl implements InternetService{
public void connect(){
System.out.println("开始连接网络....");
}
public void disconnect(){
System.out.println("网络断开....");
}
}
class MailServiceTmpl implements MailService{
public void send(){
System.out.println("发送邮箱");
}
public void receive(){
System.out.println("接收邮箱");
}
}
class VirusServiceTmpl implements VirusService{
public void begin(){
System.out.println("开始检查病毒");
}
public void end(){
System.out.println(杀毒完毕...");
}
}
interface Menu1 extends InternetService,MailService{
}
interface Menu2 extends InternetSerice,VirusService{
}
class Menu1Impl implements Menu1{
private InternetService is;
private MailService ms;
public MenuImpl(InternetService is,MailService ms){
this.is=is;
tihs.ms=ms;
}
public void connect(){
is.connect();
}
public void disconnect(){
is.disconnect();
}
public void send(){
ms.send();
}
public void receive(){
ms.receive)();
}
}
class Menu2Impl implements Menu2{
private InternetService is;
private VirusService vs;
public Menu2Impl(InternetService is,VirusService vs){
this.is=is;
this.vs=vs;
}
public void connect(){
is.connect();
}
public void disconnect(){
is.disconnect();
}
public void begin(){
vs.begin();
}
public void end(){
vs.end();
}
}
public class ServiceDemo{
public static void main(String[] args){
InternetService is=new InternetServiceImpl();
MailService ms=new MailServiceImpl();
Menu1Impl m1=new MenuImpl(is,ms);
System.out.println("检测menu1的功能中....");
m1.connect();
m1.disconnect();
m1.send();
m1.receive();
}
}
复制代码
在复合接口设计中,如何将两个系统更完好了进行耦合呢
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2