Static

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

Can't I implement an interface with static methods?

public interface IProfileRepository {
static Profile GetProfile();
static Profile GetProfile(String username);
}

Then ProfileRepository : IProfileRepository would have these two
methods.

Thank,
Miguel
 
Hello,

Can't I implement an interface with static methods?

  public interface IProfileRepository {
    static Profile GetProfile();
    static Profile GetProfile(String username);
  }

Then ProfileRepository : IProfileRepository would have these two
methods.

Thank,
Miguel

I think an interface having static member is not much meaningful. And
it is not allowed in .Net

-Cnu
 
Hello,

Can't I implement an interface with static methods?

  public interface IProfileRepository {
    static Profile GetProfile();
    static Profile GetProfile(String username);
  }

Then ProfileRepository : IProfileRepository would have these two
methods.

You cannot do that.

Note that this is pretty meaningless anyway, as static methods are not
polymorphic. About the only case where such "static interfaces" would
be useful is when constraining generic type parameters - but,
unfortunately, they aren't there yet.
 
You cannot do that.

Note that this is pretty meaningless anyway, as static methods are not
polymorphic. About the only case where such "static interfaces" would
be useful is when constraining generic type parameters - but,
unfortunately, they aren't there yet.

I understand.

Thank You,
Miguel
 
shapper said:
Hello,

Can't I implement an interface with static methods?

public interface IProfileRepository {
static Profile GetProfile();
static Profile GetProfile(String username);
}

Then ProfileRepository : IProfileRepository would have these two
methods.

Thank,
Miguel

static methods can't use the this pointer

But in your usage, you need the this pointer to reach the hidden vtable
member which contains the details of which method to call. Therefore you
should just make these normal non-static methods.
 
Back
Top