Inheritance Design Patterns

I am writing a program in which each component has an inheritance structure, has three levels ... ui, logic and data ... where each of these levels has an interface of certain functions that all components must implement. Each of these levels also has some functions that can be written generally for the entire interface, and not repeatedly for each component.

In my opinion, the best approach would be an abstract class between the interface and the implementation of the component, which performs all the common functions (as in the related class diagram here ) ... but the inheritance rules for C # allow me to have multiple inheritance from unrealized interfaces. What will be the design of best practices to achieve this type of behavior?

+4
source share
2 answers

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

This way you can inherit each class from the corresponding common class.

Remember that you should prefer composition over inheritance.

+4
source

Each (abstract class and interface) offers its own set of advantages and disadvantages. Although Russell is right in suggesting composition over inheritance, using templates offers a program for an interface rather than an implementation (Head First Design Patterns).

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

0
source

Source: https://habr.com/ru/post/1302072/


All Articles