I have the following code:
public abstract class NavEntityController<ChildEntity> where ChildEntity : NavObservableEntity
{
public abstract void Delete(ChildEntity line);
public abstract void Update(ChildEntity line);
public abstract void Create(ChildEntity line);
public void PushChangesToNav(NavObservableCollection<ChildEntity> lines)
{
foreach (var line in lines)
{
line.ErrorLastAction = false;
EntityState previousState = line.CurrentState;
try
{
switch (line.CurrentState)
{
case EntityState.Unchanged:
break;
case EntityState.NeedsCreate:
Create(line);
line.CurrentState = EntityState.Unchanged;
break;
case EntityState.NeedsUpdate:
Update(line);
line.CurrentState = EntityState.Unchanged;
break;
case EntityState.NeedsDelete:
Delete(line);
line.CurrentState = EntityState.Deleted;
break;
}
}
catch (Exception e)
{
//...
}
}
}
}
I need a base class to inherit from this class, like such:
public class NavJobController : NavEntityController<NavObservableJob>
{
public NavJobController( {}
public override void Delete(NavObservableJob line) {//Implementation here}
public override void Update(NavObservableJob line) {//Implementation here}
public override void Create(NavObservableJob line) {//Implementation here}
//Other functionality
}
However, I do not want someone to be able to do:
NavJobController j = new NavJobController();
j.Create(new NavObservableJob());
but only would like the following method:
j.PushToNav();
//and any other public functionality in the base class to be available
Essentially, I want to force the child class to implement CRUD operations, without exposing them to the public. The ideal syntax I was hoping for is the following:
private abstract void Delete(ChildEntity line);
private abstract void Update(ChildEntity line);
private abstract void Create(ChildEntity line);