リポジトリとアクティブレコードのパターンを以下のように混在させるとどう思いますか?継承に関するリポジトリとアクティブレコードのパターンの混合
GetAll()
メソッドを実装するにはどのように継承がenvolvedですか?
class Person
{
public int Id { get; set; }
public string Name { get; set; }
public Person(int id)
{
this.Id = id;
new PersonRepository().Load(this);
}
public virtual void Save()
{
new PersonRepository().Save(this);
}
}
class Employee : Person
{
public int RegistrationNumber { get; set; }
public Employee(int id) : base(id)
{
new EmployeeRepository().Load(this);
}
public override void Save()
{
base.Save();
new EmployeeRepository().Save(this);
}
}
interface IRepository<T>
{
void Save(T x);
bool Load(T x);
IEnumerable<T> GetAll();
// Other methods removed to keep code clean
}
class PersonRepository : IRepository<Person>
{
public void Save(Person x)
{
throw new NotImplementedException();
}
public bool Load(Person x)
{
throw new NotImplementedException();
}
public IEnumerable<Person> GetAll()
{
throw new NotImplementedException();
}
}
class EmployeeRepository : IRepository<Employee>
{
public void Save(Employee x)
{
throw new NotImplementedException();
}
public bool Load(Employee x)
{
throw new NotImplementedException();
}
public IEnumerable<Employee> GetAll()
{
// How to return Person data????
throw new NotImplementedException();
}
}