O'Reilly logo

C# 3.0 Design Patterns by Judith Bishop

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix A. Appendix

Pluggable Adapter Pattern Example Code—CoolBook

See the following code for an example of the Pluggable Adapter Pattern:

using System; using System.Collections.Generic; using System.Windows.Forms; using System.Drawing; using System.Threading; // Adapter Pattern Example Judith Bishop Aug 2007 // Sets up a CoolBook // This is D-J's as changed for the book class AdapterPattern { // class SpaceBookSystem { public delegate void InputEventHandler(object sender, EventArgs e, string s); // Adapter public class MyCoolBook : MyOpenBook { static SortedList<string, MyCoolBook> community = new SortedList<string, MyCoolBook>(100); Interact visuals; public MyCoolBook(string name) : base(name) { // Create interact on the relevant thread, and start it! new Thread(delegate( ) { visuals = new Interact("CoolBook Beta"); visuals.InputEvent += new InputEventHandler(OnInput); visuals.FormClosed += new FormClosedEventHandler(OnFormClosed); Application.Run(visuals); }).Start( ); community[name] = this; while (visuals == null) { Application.DoEvents( ); Thread.Sleep(100); } Add("Welcome to CoolBook " + Name); } private void OnFormClosed(object sender, FormClosedEventArgs e) { community.Remove(Name); } private void OnInput(object sender, EventArgs e, string s) { Add("\r\n"); Add(s, "Poked you"); } public new void Poke(string who) { Add("\r\n"); if (community.ContainsKey(who)) community[who].Add(Name, "Poked you"); else Add("Friend " + who + " is not part of the community"); } public new ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required