Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 15. Building a Reusable Config C... > Using Composition for Event Dispatch...

15.3. Using Composition for Event Dispatching

Typically, to gain the ability to dispatch events, you would simply subclass the EventDispatcher class (or a class that subclasses it). However, in this situation you are already subclassing the Proxy class, so you must take an alternative approach. The proper way to handle this is to use a combination of composition and the implementation of the IEventDispatcher interface. In other words, create a new EventDispatcher instance and store it in a property of your Config class.

Next, implement the IEventDispatcher interface, which will mandate that you have the same methods as the EventDispatcher class available in your Config class. Inside these methods, you will simply pass the call and parameters along to your EventDispatcher instance, as shown in Listing 15.7.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint