Reflection alternative for switch on enum in order to select namespace/class
- by Am
Hi,
I have an interface named IHarvester.
There are 3 implementations of that interface, each under their own namespace:
Google
Yahoo
Bing
A HarvesterManager uses the given harvester. It knows the interface and all 3 implementations.
I want some way of letting the class user say in which harvester it wants to use. And in the code select that implementation, without a switch-case implementation.
Can reflection save my day?
Here is the code bits:
// repeat for each harvester
namespace Harvester.Google
{
public abstract class Fetcher : BaseHarvester, IInfoHarvester {...}
}
public enum HarvestingSource
{
Google,
Yahoo,
Bing,
}
class HarvesterManager {
public HarvestingSource PreferedSource {get;set;}
public HarvestSomthing()
{
switch (PreferedSource) .... // awful...
}
}
Thanks.
I will give my 2 cents of why I want to change this. There several people writing harvesters, I want them to focus only on building more harvesters, without ever needing to update the enum, or at worst, update only the enum.