Another approach to separating common blueprints and sharing them between objects is the abstract class. Like interfaces, abstract classes cannot include any implementation logic for their methods; they can, however, store variable values. Any class that subclasses from an abstract class must fully implement all variables and methods marked with the abstract keyword. They can be particularly useful in situations where you want to use class inheritance without having to write out a base class' default implementation.
For example, let's take the IManager interface functionality we just wrote and turn it into an abstract base class instead:
// 1
public abstract class BaseManager
{
// 2
protected string _state;
public abstract string state { get; set; }
// 3
public abstract void Initialize();
}
Let's break down the code:
- First, it declares a new class named BaseManager using the abstract keyword.
- Then, it creates two variables...