public static void Perform() { IBird _sparrow = new Sparrow(); IToyDuck _toyDuck = new PlasticToyDuck(); // Wrap a bird in a birdAdapter so that it // behaves like toy duck IToyDuck _birdAdapter = new BirdAdapter(_sparrow); Console.WriteLine("Sparrow..."); _sparrow.Fly(); _sparrow.MakeSound(); Console.WriteLine("Toy Duck"); _toyDuck.Squeak(); // bird behaving like a toy duck Console.WriteLine("BirdAdapter..."); _birdAdapter.Squeak(); Console.WriteLine(); }
static void Main(string[] args) { LoadManager loadManager = new LoadManager(); loadManager.LoadFiles(new WordFile()); loadManager.LoadFiles(new JpgFile()); foreach (Files file in loadManager.Files) { loadManager.OpenFile(file); } Console.WriteLine("========================================="); #region Adapter BirdAdapter birdAdapter = new BirdAdapter(new Chicken()); birdAdapter.ToTweet(); birdAdapter.ShowType(); BirdAdapter ba = new BirdAdapter(new Eagle()); ba.ShowType(); ba.ToTweet(); #endregion Console.WriteLine("========================================="); #region Inheritance Bird bird = new Bird(); bird.ShowType(); Bird bird2 = new ClassLibrary.Inheritance.Eagle(); bird2.ShowType();//尋找與創建欄位最近的作存取 Console.WriteLine(bird2.type); bird2.ShowType2(); ClassLibrary.Inheritance.Eagle eagle = new ClassLibrary.Inheritance.Eagle(); eagle.ShowType(); eagle.ShowType2(); #endregion Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("ADAPTOR DESIGN PATTERN\n"); Console.WriteLine("----------"); Bird raven = new Bird("Raven"); PlasticToyDuck toyDuck = new PlasticToyDuck("Duck toy"); // wrapper a bird into an adapter // in order to make a bird behave like a toyduck IToyDuck birdAdapter = new BirdAdapter(raven); raven.Fly(); raven.MakeSound(); toyDuck.Squeak(); birdAdapter.Squeak(); }