I am trying to build a core application that uses plugins so that the core never changes and each time we get a new client we write a module for them. We implement a interface called IClientPlugin with the new customer class.
This is using Compact Framework 3.5 and windows mobile 6.5.3.
So here is what I need to acheive:
this is a warehouse management system. The first task is to receive in the product from a truck scanning barcodes off packages with the handheld device.
The core module for this is started when the person clicks the receiving menu item.
the core method is – callClientMethod()
I know the client name and it is stored in a global variable at login and the class will be {clientname}.cs
and contain a method called processReceiving().
I know how to instantiate this object.
The question is: is there a way I can dynamically create a instance of the client class without hardcoding case statements?
For example suppose I have 2 clients Acme and Widgets. They each get a client class, namely Acme.cs and Widgets.cs
If I login as Acme or Widgets I want the code to dynamically create a instance of the Client class that I logged in as so that the core code does not have to change as I add more clients as long as I add a module for them.
psuedo example:
var myClient = New (Clientname)();
Is this possible or is there a better design approach or is the switch/case statement a neccessary evil?
You can use reflection to create objects dynamically.
There are many ways to load a type or assembly. Lets start with a simple one:
If your client is named myClient1 and you have the convention, that your assemblies are named for example like Clients.ClientName.dll then you can write a function:
EDIT
If your plugin classes are located in the same assembly as your main project, you can simplify the call of Type.GetType to just specify the classname: