1.把窗帘拉下来。
2.摆好椅子。
3.降下投影幕布。
4.打开投影仪。
5...............
太烦了,有时你甚至少做了一样,别怕,如果有了外观模式就可以高枕无忧了。简单的说,外观模式就是把1~5条甚至更多的操作抽象为一个操作,那就是------------开会布置
在本例中,外观模式就是把游戏初始化的操作合并为一个操作,Game类中的GameStart。
此模式比较好理解,具体请see完整代码哟。
测试代码:
DotaPatternLibrary.Facade.Game game = new DotaPatternLibrary.Facade.Game();
game.GameStart();
完整代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotaCommon;
namespace DotaPatternLibrary.Facade
{
public class Game
{
public void GameStart()
{
HeroFactory heroFactory = new HeroFactory();
heroFactory.CreateModel();
heroFactory.SetSkill();
heroFactory.Maps();
BotWildNPC botWildNPC = new BotWildNPC();
botWildNPC.CreateModel();
botWildNPC.Maps();
Music music = new Music();
music.SelectMusic();
music.Play();
Terrain terrain = new Terrain();
terrain.RandomTerrain();
terrain.Maps();
}
}
internal class HeroFactory
{
public void CreateModel()
{
LandpyForm.Form.OutputResult("CreateHeroModel");
}
public void SetSkill()
{
LandpyForm.Form.OutputResult("SetHeroSkill");
}
public void Maps()
{
LandpyForm.Form.OutputResult("MapsHero");
}
}
internal class BotWildNPC
{
public void CreateModel()
{
LandpyForm.Form.OutputResult("CreateBotWildNPCModel");
}
public void Maps()
{
LandpyForm.Form.OutputResult("MapsBotWildNPC");
}
}
internal class Music
{
public void SelectMusic()
{
LandpyForm.Form.OutputResult("SelectMusic");
}
public void Play()
{
LandpyForm.Form.OutputResult("MusicPlay");
}
}
internal class Terrain
{
public void RandomTerrain()
{
LandpyForm.Form.OutputResult("RandomTerrain");
}
public void Maps()
{
LandpyForm.Form.OutputResult("MapsTerrain");
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotaCommon;
namespace DotaPatternLibrary.Facade
{
public class Game
{
public void GameStart()
{
HeroFactory heroFactory = new HeroFactory();
heroFactory.CreateModel();
heroFactory.SetSkill();
heroFactory.Maps();
BotWildNPC botWildNPC = new BotWildNPC();
botWildNPC.CreateModel();
botWildNPC.Maps();
Music music = new Music();
music.SelectMusic();
music.Play();
Terrain terrain = new Terrain();
terrain.RandomTerrain();
terrain.Maps();
}
}
internal class HeroFactory
{
public void CreateModel()
{
LandpyForm.Form.OutputResult("CreateHeroModel");
}
public void SetSkill()
{
LandpyForm.Form.OutputResult("SetHeroSkill");
}
public void Maps()
{
LandpyForm.Form.OutputResult("MapsHero");
}
}
internal class BotWildNPC
{
public void CreateModel()
{
LandpyForm.Form.OutputResult("CreateBotWildNPCModel");
}
public void Maps()
{
LandpyForm.Form.OutputResult("MapsBotWildNPC");
}
}
internal class Music
{
public void SelectMusic()
{
LandpyForm.Form.OutputResult("SelectMusic");
}
public void Play()
{
LandpyForm.Form.OutputResult("MusicPlay");
}
}
internal class Terrain
{
public void RandomTerrain()
{
LandpyForm.Form.OutputResult("RandomTerrain");
}
public void Maps()
{
LandpyForm.Form.OutputResult("MapsTerrain");
}
}
}