I have two classes Say A and B which has method set().
public Class A : I<string>
{
void Set(string str)
{
//do something
}
}
public Class B : I<int>
{
void Set(int str)
{
//do something
}
}
And an interface as follows...
interface I<T>
{
void Set(T param);
}
I would like to access this method without instantiating the classes, through interface (Is it possible or is there any other way like dependency injection?).
From another Class
Class D
{
I.Set(<T> str); //something like this
}
So based on data type I need to redirect the call from either interface or some where, so that if tomorrow I added a class say C which implements same interface, I should not end up with changing code in D.
Thanks in Advance...
AorB(or some futureC), on what are you actually expecting to set values?I.Set()since an interface is nothing more than a contract, it's not an actual object in memory that is instantiated.