brettlj wrote:
Excellent and much-needed discussion.
I regularly create my own entity classes that inherit from LLBLGen-created entity classes, partly as a way of achieving a degree of abstraction, partly so that I can later add my own properties to an entity that are not persisted in the database.
This is soon not necessary anymore with the custom includes functionality build in Beta 2 released yesterday
Your comment on using interfaces implemented by the subclass-entities caught my attention because it is something I've thought about for awhile. Much of the literature I've read seams to suggest that creating interfaces and then programming to them rather than the classes themselves is a good thing. However, I have difficulty seeing the benefit of using interfaces in this situation, especially when I consider the amount of work that would have to go into creating and maintaining an interface for every entity. I fully understand the benefits of using interfaces to sort of simulate multiple inheritance, but struggle to understand the benefits of programming to an interface of an entity class.
Interfaces are introduced as a tool to, as you already mention, include multiple inheritance, or better: multiple TYPE inheritance. .NET and Java don't support multiple implementation inheritance.
A class also has an interface. This is the reason why I use IEntity and IEntity2 inside the generic code: an entity class in fact implements 2 types: its own type, for example CustomerEntity, and IEntity (or IEntity2). (it implements even more interfaces actually). To see an object as an instance of a given type, IEntity, CustomerEntity, ISerializable, EntityBase etc., use a reference variable of that type and give that variable a reference to the object.
Does it really provide more abstraction to do this:
ICustomer cust = CustomerManager.GetSingleCustomer(custId);
txtFirstName.Text = cust.FirstName;
as opposed to this?:
Customer cust = CustomerManager.GetSingleCustomer(custId);
txtFirstName.Text = cust.FirstName;
That depends on how you defined 'Customer'. If that's a derived class from a generated entity class, 'Customer' exposes a much bigger set of members than ICustomer, which for example only exposes the bare properties and 1 or 2 methods.
@Fishy: Code snippets are often very database specific. I think theory is more important than a snippet of a sales order class with entities and relations that are not matching your database, or do you see this differently?