public GooseToDuckAdapter(Goose gooseToAdapt) { this.gooseToAdapt = gooseToAdapt; }
// Adapter pattern void quackTheDucks_Click(object sender, EventArgs e) { List<IQuackable> ducksToQuack = new List<IQuackable>(); // Let's create some ducks - shows the beauty of interfaces MallardDuck mallardDuck = new MallardDuck(); ducksToQuack.Add(mallardDuck); RubberDuck rubberDuck = new RubberDuck(); ducksToQuack.Add(rubberDuck); DuckDecoy duckDecoy = new DuckDecoy(); ducksToQuack.Add(duckDecoy); // Add a goose adapter to show the adapter pattern Goose goose = new Goose(); GooseToDuckAdapter gooseToDuckAdapter = new GooseToDuckAdapter(goose); ducksToQuack.Add(gooseToDuckAdapter); OutputData(ducksToQuack); }