I have Person.cs
which will be implemented by, for example, the Player
class.
Person
has an ExperienceLevelType
property.
I want to force all classes that derived from Person
to implement their own version of the ExperienceLevelType
property.
public abstract Person
{
public enum ExperienceLevel { Kid, Teenager}
public virtual ExperienceLevel Experience {get; set;}
}
public abstract Player:Person
{
public override ExperienceLevel Experience
{
}
}
That's what abstract
is for:
public abstract class Person
{
public enum ExperienceLevel { Kid, Teenager}
public abstract ExperienceLevel Experience { get; set; }
}
If you want to force derived classes to implement the property themselves while at the same time providing some reusable scaffolding to help them, expose the scaffolding as protected
members inside Person
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With