Skip to content

Instantly share code, notes, and snippets.

@devknoll
Created July 20, 2012 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devknoll/3153716 to your computer and use it in GitHub Desktop.
Save devknoll/3153716 to your computer and use it in GitHub Desktop.
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