Interface vs. Base class is still a fairly gray area to me. I’m reading a book on ASP.NET 3.5 Enterprise Development and the author states that all tables will have the following fields:
InsertDate
InsertENTUserAccountId
UpdateDate
UpdateENTUserAccountId
Version
If this were me coding the above requirement, I would create a base business object class that contained these fields, and all business objects would inherit from it. However, the author has created these as an Interface instead. Bad idea? Good idea? Doesn’t matter?
Update
There is a base class that implements this Interface. It appears that all business objects would then inherit from the base. But even still, I would have just put this Interface in the base class…?
By using an interface you are required to implement all those properties in all classes that implement the interface. If the implementation is the same for all, this is a lot of duplicated code. This can be mitigated by having a base class implement the interface.
By using a base class you can share the same implementation among all subclasses. Problems arise if you need to subclass something else, as .NET does not allow multiple inheritance. This way you will have to directly implement the interface (probably using composition).