Skip to main content
added 197 characters in body
Source Link
Guran
  • 545
  • 2
  • 9

An alternative solution (which I would not generally recommend, but accomplishes what you are after) would be this.

public virtual class Switch //make sealed if you really want to enforce behaviour {    public bool IsEnabled {get; private set;} public void Enable() //make virtual if you don't want to enforce this behaviour {  IsEnabled = true; } public void Disable() //make virtual if you don't want to enforce this behaviour  { IsEnabled = false; } } public interface IComponent { Switch Switch{get;} } 

An alternative solution (which I would not generally recommend, but accomplishes what you are after) would be this.

public virtual class Switch { bool IsEnabled {get; private set;} public void Enable() { IsEnabled = true; } public void Disable() { IsEnabled = false; } } public interface IComponent { Switch Switch{get;} } 

An alternative solution (which I would not generally recommend, but accomplishes what you are after) would be this.

public class Switch //make sealed if you really want to enforce behaviour {    public bool IsEnabled {get; private set;} public void Enable() //make virtual if you don't want to enforce this behaviour {  IsEnabled = true; } public void Disable() //make virtual if you don't want to enforce this behaviour  { IsEnabled = false; } } public interface IComponent { Switch Switch{get;} } 
Source Link
Guran
  • 545
  • 2
  • 9

An alternative solution (which I would not generally recommend, but accomplishes what you are after) would be this.

public virtual class Switch { bool IsEnabled {get; private set;} public void Enable() { IsEnabled = true; } public void Disable() { IsEnabled = false; } } public interface IComponent { Switch Switch{get;} }