public class Employee : IEmployee
{
private String name;
private String department;
private int salary;
private List<IEmployee> subordinates;
public void addEmployee(String name, String department, int salary)
{
this.name = name;
this.department = department;
this.salary = salary;
}
public void addSubordinate(IEmployee e)
{
subordinates.add(e);
}
interface IEmployee
{
void addEmployee(String name, String department, int salary);
String getEmployeeInfo();
void addSubordinate(IEmployee e);
}
public void If_We_Add_Alan_As_Johns_Subordinate_We_SHould_get_that()
{
ObjectFactory.Configure(x =>
{
x.For<IEmployee>().Use<Employee>();
});
var DairyManager = ObjectFactory.GetInstance<IEmployee>();
var Cashier = ObjectFactory.GetInstance<IEmployee>();
Cashier.addEmployee("Alan", "cashier", 1000);
DairyManager.addEmployee("John", "CEO", 10000);
DairyManager.addSubordinate(Cashier);
錯誤說:我得到一個「可訪問性不一致」錯誤
可訪問性不一致:參數類型
IEmployee
比方法Employee.addSubordinate(Supermarket.IEmployee)
不太容易接近...