Active Events - The Only Design Pattern You Need

Active Events is a design pattern yours truly invented several years ago. It features some unique traits, since it allows you to completely decouple your different components into modules and plugins. Some would argue it completely replaces OOP, but that tends to scare people away from it, thinking "gosh, I'll have to learn something new and difficult". Others like to ease in the pain, and explain it for what it is, which is that it replaces the methods and function invocations you have, that goes cross modules and components, with loosely coupled reflection based, dynamically loaded assemblies, able to invoke methods in other assemblies through a simple string based dictionary lookup.

To create an Active Event is dead simple.

code

  1. [ActiveEvent(Name = "foo")]  
  2. private static void (ApplicationContext context, ActiveEventArgs e)  
  3. {  
  4.    /* ... do stuff with e.Args here ...*/  
  5. }  
To consume an Active Event, is equally dead simple.

code
  1. /* ... somewhere in your own C# code ...*/  
  2. var input = new Node ("foo", someVariable);  
  3. var output = context.Raise ("foo", input);  
Exactly how to create an Application Context, depends upon which framework you use implementing the Active Event design pattern.

The advantage with the above construct, is that you no longer have any interfaces or classes that you need to share between your different components. The invocation of "foo" above, is simply a lookup into a Dictionary object, which in turn contains MethodInfo objects, which is dynamically loaded during startup of your app.

This completely de-couples your modules, allowing you to create a higher level of encapsulation and cohesion, where none of your existing components, are dependent upon each other.

This in turn, give you a much higher flexibility, and creates more "Agile" software for you, where you can construct software, more like you would use LEGO in your childhood. This in turn, makes all your code extremely reusable!

A good implementation of the Active Event design pattern, also allows you to register instance listeners, which are instances of classes, where your have non-static methods, which are registered as Active Event handlers. However, since this article is an introductory article, to the design pattern, from a high abstraction level, I will leave that up to another article.

The real beauty of the Active Event design pattern, is that it replaces almost every other design pattern on the planet, including the original 23 design patterns from the gang of four, in their famous book "Design Patterns".

For instance, an abstract factory is completely redundant, since you can dynamically create the string, which in the above invocation to ApplicationContext.Raise, chooses which Active Event to invoke. This allows you to dynamically create a string, which literally chooses which underlying method to invoke, through the Active Event engine.

I could go on like this, for almost all other design patterns. However, I have left that as an exercise for the reader.

The author of this article, has been working on an Open Source library, written entirely in C#, which happens to implement the Active Event design pattern. To see this code, and some of the results, going down this rabbit hole, check out the author's GitHub project page.

Or follow my blog over at https://gaiasoul.com.

 

Next Recommended Reading C# Corner Webinar on Design Pattern