static void Main(string[] args) { var turkey = new WildTurkey(); var adapter = new TurkeyAdapter(turkey); Tester(adapter); }
static void Main(string[] args) { IDuck duck = new Duck(); ITurkey turkey = new Turkey(); IDuck turkeyAdapter = new TurkeyAdapter(turkey); Console.WriteLine(); duck.Fly(); duck.Quack(); Console.WriteLine(); turkey.Fly(); turkey.Gobble(); Console.WriteLine(); turkeyAdapter.Fly(); turkeyAdapter.Quack(); Console.WriteLine(); Action(duck); Console.WriteLine(); Action(turkeyAdapter); Console.ReadKey(); }
// Definicja książkowa //Tworzymy klasę adapter która implementuje interfejs IDuck, a indyka wstrzykujemy do niej przez konstruktor. //Dzięki takiemu zabiegowi można w klasie która z definicji jest kaczką (implementuje interfejs IDuck) podmienić zachowanie kwakania na //gęganie :) //public void Quack() //{ // _turkey.Gobble(); //} private static void Main() { var turkey = new WildTurkey(); var adapter = new TurkeyAdapter(turkey); Tester(adapter); }
static void Main(string[] args) { /* Aquí se crean el pato y el pavo, como puedes ver ambos implementan * su propia interfaz con metodos como volar, graznar o gluglutear * * Entra a las clases MallardDuck y WildTurkey */ MallardDuck duck = new MallardDuck(); WildTurkey turkey = new WildTurkey(); //El adaptador convierte la interfaz de pato para ser utilizada por un pavo //sin problemas. //entra a la clase TurkeyAdapter IDuck turkeyAdapter = new TurkeyAdapter(turkey); //Aquí probaremos los métodos del pavo Console.WriteLine("The Turkey says..."); turkey.Gobble(); turkey.Fly(); //Aquí probaremos los métodos del pato Console.WriteLine("\nThe Duck says..."); TestDuck(duck); //Aquí probaremos los métodos el adaptador //(llamamos los metodos del pato pero se ejecutan como pavo) Console.WriteLine("\nThe TurkeyAdapter says..."); TestDuck(turkeyAdapter); Console.ReadKey(); //Ejecuta el proyecto para ver el resultado //Como podrás ver se pudo utilizar la interfaz de pato para llamar métodos //de un pavo y esto no afecto el funcionamiento }
static void Main(string[] args) { var turkey = new WildTurkey(); var turkeyAdapter = new TurkeyAdapter(turkey); turkeyAdapter.Fly(); turkeyAdapter.Quack(); }
private static void Main() { var turkey = new WildTurkey(); var duck = new MallardDuck(); var adapter = new TurkeyAdapter(turkey); var duckadapter = new DuckAdapter(duck); Tester(adapter); Tester(duckadapter); }
private static void Main(string[] args) { var expected = "gobble gobble"; WildTurkey turkey = new WildTurkey(); TurkeyAdapter turkeyAdapter = new TurkeyAdapter(turkey); TestDuck(turkeyAdapter); Console.WriteLine(turkeyAdapter.Quack()); }
static void DuckTestDrive() { IDuck duck = new MallardDuck(); var turkey = new WildTurkey(); IDuck turkeyAdapter = new TurkeyAdapter(turkey); System.Console.WriteLine("Turkey says........."); turkey.Gobble(); turkey.Fly(); System.Console.WriteLine("Duck says........."); TestDuck(duck); System.Console.WriteLine("TurkeyAdapter says........."); TestDuck(turkeyAdapter); }
static void Main(string[] args) { MallardDuck duck = new MallardDuck(); WildTurkey turkey = new WildTurkey(); IDuck turkeyAdapter = new TurkeyAdapter(turkey); Console.WriteLine("The turkey says..."); turkey.Gobble(); turkey.Fly(); Console.WriteLine("\nThe duck says..."); TestDuck(duck); Console.WriteLine("\nThe adapted turkey says..."); TestDuck(turkeyAdapter); }
static void Main(string[] args) { MallardDuck duck = new MallardDuck(); WildTurkey turkey = new WildTurkey(); Duck adapter = new TurkeyAdapter(turkey); Console.WriteLine("The turkey says..."); turkey.Google(); turkey.fly(); Console.WriteLine("The duck says..."); duck.quack(); duck.fly(); Console.WriteLine("The adapter says ..."); adapter.quack(); adapter.fly(); Console.ReadKey(); }
static void Main(string[] args) { var duck = new MallardDuck(); var turkey = new WildTurkey(); var turkeyAdapter = new TurkeyAdapter(turkey); Console.WriteLine("The turkey says: "); turkey.Gobble(); turkey.Fly(); Console.WriteLine("\nThe Duck says: "); duck.Quack(); duck.Fly(); Console.WriteLine("\nThe turkeyAdapter says:"); testDuck(turkeyAdapter); }
static void Main(string[] args) { MallardDuck duck = new MallardDuck(); WildTurkey turkey = new WildTurkey(); Console.WriteLine("The turkey says :"); turkey.Gobble(); turkey.Fly(); Console.WriteLine("The duck says"); duck.Quack(); duck.Fly(); TurkeyAdapter adapter = new TurkeyAdapter(turkey); adapter.Quack(); adapter.Fly(); }
static void Main(string[] args) { MallardDuck duck = new MallardDuck(); WildTurkey turkey = new WildTurkey(); var turkeyAdapter = new TurkeyAdapter(turkey); Console.WriteLine("The Turkey says......."); turkey.gobble(); turkey.fly(); Console.WriteLine("The Duck says......."); testDuck(duck); Console.WriteLine("The TurkeyAdapter says..."); testDuck(turkeyAdapter); Console.ReadLine(); }
static void Main(string[] args) { /*both sides*/ ITurkey turkey = new TurkeyDuckAdapter(); turkey.Fly(); turkey.Gobble(); /*Turkey to duck*/ Turkey turkeyy = new Turkey(); IDuck turkeyAdapter = new TurkeyAdapter(turkeyy); Console.WriteLine("----------------------------------"); turkeyAdapter.Fly(); turkeyAdapter.Quack(); Console.ReadKey(); }
static void Main(string[] args) { var duck = new MallardDuck(); var turkey = new WildTurkey(); var turkeyAdapter = new TurkeyAdapter(turkey); Console.WriteLine("The Turkey says..."); turkey.Gobble(); turkey.Fly(); Console.WriteLine("The Duck says..."); TestDuck(turkeyAdapter); var duckAdapter = new DuckAdapter(duck); TestTurkey(duckAdapter); }
static void Main(string[] args) { MallardDuck duck = new MallardDuck(); WildTurkey turkey = new WildTurkey(); Duck turkeyAdapter = new TurkeyAdapter(turkey); System.Console.WriteLine("The Turkey says..."); System.Console.WriteLine(turkey.Gobble()); System.Console.WriteLine(turkey.Fly()); System.Console.WriteLine("\n The Duck says..."); testDuck(duck); System.Console.WriteLine("\n The TurkeyAdapter says..."); testDuck(turkeyAdapter); System.Console.ReadKey(); }
private static void Main(string[] args) { var duck = new MallardDuck(); var turkey = new WildTurkey(); var turkeyAdapter = new TurkeyAdapter(turkey); Console.WriteLine("The turkey says..."); turkey.Gobble(); turkey.Fly(); Console.WriteLine("Duck says..."); TestDuck(duck); Console.WriteLine("The turkeyAdapter says..."); TestDuck(turkeyAdapter); Console.ReadLine(); }
static void Main(string[] args) { //Mallard duck is the target class which is derived from IDuck //WildTurkey is the adaptee derived from ITurkey //TurkeyAdapter is the adapter which adapts to IDuck which client knows so implements IDuck //But since the behaviour is of type WildTurkey an instance of WildTurkey is passed in the constuctor. /*If we have a third party API and client does not know about these api's then we can come up with the class * which is derived from the class known to the client and provide a constructor which takes the third party API instance * Each of the methods in the known class will be modified to call the third pary api.*/ Console.WriteLine("\nThis is Mallard actions:"); IDuck mallardDuck = new MallardDuck(); mallardDuck.Quack(); mallardDuck.Fly(); Console.WriteLine("\nThis is Wild Turkey actions:"); ITurkey wildTurkey = new WildTurkey(); wildTurkey.Gobble(); wildTurkey.Fly(); \ IDuck turkeyAdapter = new TurkeyAdapter(wildTurkey); Console.WriteLine("\nThis is Duck Adapter actions:"); TestDuck(turkeyAdapter); DuckAdapter duckAdapter = new DuckAdapter(mallardDuck); Console.WriteLine("\nThis is Turkey Adapter actions:"); TestDuck(duckAdapter); IDuck classAdapter = new ClassAdapter(wildTurkey); Console.WriteLine("\nThis is class Adapter actions:"); TestDuck(classAdapter); Console.ReadLine(); }