I would like to design a plugin framework, but I have not been able to find an object oriented design that fits my objectives.

My broader design goal is for me to let users define classes in a directory. Then, the program would load the classes at run time. The classes would share a common interface such that the program could iterate over the classes, and call a method which each class would share. For instance:


Would call the .run method of all the modules loaded by the framework. The reason this approach is attractive to me is that users would be able to provide their classes with custom code, that could be run en masse at run time without having to add "include" statements and whatnot to load the class at initialization.

However, as far as I know this design does not easily meld with standard object oriented design. For instance, most languages don't expose a way to iterate over every existing subclass of a class and call a common method. I must be incorrectly conceptualizing how I would accomplish this.

The primary existing example of such a framework I know of is the metasploit framework.

What would be the correct design for such a project? I feel the main difference between this and standard plugin pattern, is that the plugins must be loaded at run time and iterated over to call a common method.

  • "...most languages don't expose a way to iterate over every existing subclass of a class and call a common method" - Yes they do. It's called Class Reflection. Many languages, including PHP, Java, C#, and Ruby, support this. – Greg Burghardt Mar 8 '17 at 21:21
  • Here is a example from the c# universe. – John Wu Mar 8 '17 at 21:26
  • @JohnWu Nice example! – wogsland Mar 9 '17 at 1:02
  • Here's how I did it in Java: ScriptManager.java Note particularly the findScriptClasses method. I think this question is too broad without specifying a language, and once you specify a language, it probably belongs on SO. – Kevin Krumwiede Mar 9 '17 at 5:33
  • I am actually crafting a language specific version, but I got off on tangent about asking about the correct object hierarchy, that's why I'm asking here. FWIW I'd like to know in the abstract anyway, but it's in powershell. – baordog Mar 9 '17 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.