Is there a way to impose some methods to a class without specify the parameters?
I have a class named MANAGER
public abstract class MANAGER
{
}
Nothing complex :-)
This class have multiple subclasses example AD_MANAGER
public class AD_MANAGER : MANAGER
{
#region MEMBRES
private AD_PROVIDER ad_provider;
#endregion
//================================================================================
#region ACCESSEURS
public AD_PROVIDER Ad_provider
{
get { return ad_provider; }
set { ad_provider = valu开发者_如何学Goe; }
}
#endregion
//================================================================================
#region CONSTRUCTORS
public AD_MANAGER()
{
this.ad_provider = new AD_PROVIDER();
}
#endregion
//================================================================================
#region Public methods
#region Get
Stuff Here ..
#endregion
#endregion
}
And other ones.. Each Manager "manage" a specific class, named ENTITE. So for AD_MANAGER is used to manage a AD_ENTITE the ENTITE class contains only fields no methods..
So here's my question: How can I specify that every MANAGER class have to implement a method for example isNull() but with parameters of type _ENTITE class related..
So AD_MANAGER Have to implement a bool isnull(AD_ENTITE aENTITE)
method, and PERS_MANAGER Have to implement bool isnull(PERS_ENTITE aPERS)
method.
With interface you can't declare bool isnull(anytype);
So how can I do this such thing?
Thank you for trying to help me!
Create an interface:
public interface IAdManager<T>
{
bool IsNull(T obj);
}
Then your client classes need to implement IAdManager
like:
public class AD_MANAGER : MANAGER, IAdManager<AD_MANAGER>
Yes, generics probably will help.
public abstract class MANAGER<T>
{
public abstract bool isnull(T item);
}
and
public class AD_MANAGER : MANAGER<Ad_provider>
{
public override bool isnull(Ad_provider item) {
}
}
Generics should help you achieve this, I guess!
Can you use two different interfaces IAd_Manager and IPers_Manager?
Or alternatively declare the method as:
bool isnull(T myParam);
精彩评论