I have completely confused myself trying to design the necessary interfaces and abstracts to accomplish loading of domain entities that can be used by themselves as well as combined into an aggregate. Wow. That was a buzzword mouthful. Essentially, I have two objects that I would like to have base-type "load" functionality, but when these two objects are combined into one, I run into multiple inheritance.
So, I have my entities, which are like this (I'd draw
public class Account
public class Document
public class AccountDocument
{
public Account Account{get;set;}
public Document Document{get;set;}
}
Then, I have interfaces, like this:
public interface IAccountRepository
{
Account Load(IDataContext context);
}
public interface IDocumentRepository
{
Document Load(IDataContext context);
}
public interface IAccountDocumentRepository
{
AccountDocument Load(IDataContext context);
}
Since both Account and Document can (and are) being derived from for other entities, I want to provide base functionality in the implementation so that I follow DRY.
public abstract class AccountRepositoryBase : IAccountRepository
{
Account Load(IDataContext context)
{
//implementation for loading the Account from the context
}
}
public abstract class DocumentRepositoryBase : IDocumentRepository
{
Document Load(IDataContext context)
{
//implementation for loading the Document from the context
}
}
This works fine for the individual Account and Document objects and their derivations, but the problem I can't seem to wrap my head around is how to handle the AccountDocument...
public class AccountDocumentRepository : AccountRepositoryBase, DocumentRepositoryBase
{
//This is not possible, of course, due to multiple inheritance.
}
I know the solution can't be that hard, but I am completely tangled up and can't straighten out how I can provide the base "Load" functionality only once. Please help!
Thanks in advance.