Let's assume we have the following class:
public class Employee
{
public string Name { get; private set; }
public string Team { get; private set; }
public Employee(string name, string team)
{
this.Name = name;
this.Team = team;
}
public void UpdateName(string newName, string updatedBy)
{
this.Name = newName;
this.Update(updatedBy);
}
public void UpdateTeam(string newTeam, string updatedBy)
{
this.Team = newTeam;
this.Update(updatedBy);
}
private void Update(string updatedBy)
{
// and do something with updatedBy
}
}
Is there a better way in C# I can enforce a method (e.g. UpdateTeam
to call Update
method and pass it a string parameter - e.g. updatedBy
)?
Of course there is no such syntax, but just to illustrate what I mean:
public class Employee
{
// ...
public void UpdateTeam(string newTeam, string updatedBy) : Update(updatedBy)
{
this.Team = newTeam;
}
private void Update(string updatedBy)
{
// and do something with updatedBy
}
}
Edit: I know about the 'Template' pattern, it's NOT what I need.