I've got two classes : Unit and User.
a Unit class has a User as leader, and a User can be part of many units.
class Unit
{
User Leader;
public void SetLeader(User leader)
{
this.Leader=leader;
}
}
class User
{
Unit UnitLed;
public void LeadUnit(Unit unit)
{
this.UnitLed=unit;
unit.SetLeader(this);
}
}
Howw can I enforce it so that a developer using these classes DOES NOT mistakenly call a code such as :
User _user=new User();
Unit _unit=new Unit();
_user.LeadUnit(_unit);
_unit.SetLeader(_user);
but that people use the classes in this way :
_user.LeadUnit(_unit)