Explicit interface implementation for classes in C# -
is there comparable explicit interface implementation classes instead in c#?
consider following situation:
company x provides library containing class follows:
public class libraryclass { public virtual void a() { } public void dowork() { // } } company y uses library in 1 of products , inherits libraryclass:
public class userclass : libraryclass { public virtual void b() { } } so far works fine. @ someday x releases new library version , adds virtual method b()to libraryclass:
public class libraryclass { public virtual void a() { } public virtual void b() { } public void dowork() { // // uses b semantic assumptions } } now y updates new library version. while compiling reference new version, compiler emits warning saying userclass.b() hiding inherited method libraryclass.b() , therefore should either specify new keyword or override method. because there semantic gap between existing method userclass.b() , newly introduced method libraryclass.b() y decides introduce new keyword because existing override of userclass.b() not provide semantics expected dowork() break code. on other hand y wants use new feature of library require override of libraryclass.b(). not possible: if override done in derived class of userclass override refer userclass.b() due new keyword; override of b in userclass not allowed defines public method signature.
this situation solved if there either way in derived class of userclass specify override refers libraryclass.b() not possible far know -or- if b() explicitly overriden in userclass:
public class userclass : libraryclass { ... // override method in order change behavior of libraryclass.b() public virtual void libraryb() { } private void override libraryclass.b() { libraryb(); } ... } is there way in language solve situation other renaming original b() in userclass (which might not possible if part of library consumed company z)? if not, c# limitation or limitation of clr?
sorry long post , thank reading point.
edit: not clr limitation. c++/cli supports named overrides solve situation, virtual void libraryb(void) = libraryclass::b;. c# design team missed issue.
is there way in language solve situation other than...
no, there isn't. if genuinely feel risk, perhaps use interface-based design rather inheritance. personally, feel unlikely going cause significant issue, if use more specific method names b().
Comments
Post a Comment