views:

105

answers:

2

I'm writing a program where each component has an inheritance structure has three levels... ui, logic, and data... where each of these levels has an interface of defined functionality that all components must implement. Each of these levels also has some functionality that could be written generically for the whole interface, rather than repeatedly for each component.

In my mind, the best approach would be an abstract class in between the interface and the component implementation that does all the generic functionality (as in the linked class diagram here)... but the inheritance rules for C# only let me have the multiple inheritance from unimplemented interfaces. What would be a best practices design to achieve this type of behavior?

+4  A: 

Why not have each one of the components (UI, logic and data) in a different class and then have the UI using the logic class then have the logic class use the data class.

That way you could have each class inherit from the appropriate generic class.

Remember, you should prefer composition over inheritance

Russell Giddings
Ah, that does make much more sense.
tbischel
A: 

Each (abstract class & interface) offers their own set of advantages and disadvantages. While Russell is correct in suggesting composition over inheritance, using patterns suggests program to an interface, not an implementation (Head First Design Patterns).

An abstract class offers tons of flexibility where you can implement methods under the covers so to speak, enforce implementation, etc. Both interfaces offer polymorphism if that is a concern. But abstract classes take a base inheritance slot.

dboarman