Created
July 20, 2012 22:44
-
-
Save devknoll/3153716 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface IMyInterface | |
{ | |
String Name { get; } | |
} | |
abstract class MyBaseClass : IMyInterface | |
{ | |
// We MUST write this stub or it fails to compile for | |
// not implementing IMyInterface - despite being abstract. | |
public abstract String Name { get; } | |
} | |
class MyDerivedClass : MyBaseClass | |
{ | |
// Fails to compile because MyBaseClass doesn't specify a set accessor! | |
public override String Name | |
{ | |
get; | |
set; // We want to allow users who have a concrete instance of MyDerivedClass (such as a View in MVVM) | |
// to be able to set a new value here. | |
} | |
} | |
// ******************************************************************** | |
// It is possible to work around this by instead doing the following... | |
// But notice that MyBaseClass can no longer implement IMyInterface | |
// or more importantly, (safely) refer to "this" as IMyInterface. | |
// ******************************************************************** | |
interface IMyInterface | |
{ | |
String Name { get; } | |
} | |
abstract class MyBaseClass | |
{ | |
// ... | |
} | |
class MyDerivedClass : MyBaseClass, IMyInterface | |
{ | |
public String Name { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment