Java 设计模式 之 门面模式
Posted verejava
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java 设计模式 之 门面模式相关的知识,希望对你有一定的参考价值。
http://www.verejava.com/?id=16999102164568
package com.facade.theory;
public class TestFacade
{
public static void main(String[] args)
{
Facade facade=new Facade();
facade.sing();
facade.dance();
facade.act();
}
}
package com.facade.theory;
public class Facade
{
private Light light;
private Music music;
private Video video;
public Facade()
{
light=new LightImpl();
music=new MusicImpl();
video=new VideoImpl();
}
public void sing()
{
System.out.println("开始演唱 伴随");
light.flash();
music.play();
}
public void dance()
{
System.out.println("开始跳舞 伴随");
light.flash();
music.play();
video.show();
}
public void act()
{
System.out.println("开始小品 伴随");
light.flash();
video.show();
}
}
package com.facade.theory;
public interface Light
{
public void flash();
}
package com.facade.theory;
public class LightImpl implements Light
{
@Override
public void flash()
{
System.out.println("闪彩灯");
}
}
package com.facade.theory;
public interface Music
{
public void play();
}
package com.facade.theory;
public class MusicImpl implements Music
{
@Override
public void play()
{
System.out.println("播放古典音乐");
}
}
package com.facade.theory;
public interface Video
{
public void show();
}
package com.facade.theory;
public class VideoImpl implements Video
{
@Override
public void show()
{
System.out.println("显示高山流水视频");
}
}
http://www.verejava.com/?id=16999102164568
以上是关于Java 设计模式 之 门面模式的主要内容,如果未能解决你的问题,请参考以下文章