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

阅读更多 登录后自动展开
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页