Avoiding Parallel Inheritance Hierarchies Among GUI Controls and Domain Objects

I am developing a Windows Forms application in C #. I am using the MVP design pattern. In the GUI, the user can manipulate printer objects, and the user must have custom controls that are printer objects.

There is a class hierarchy that represents printers. At the base there is an abstract printer class. Then there is the abstract class InkJetPrinter and the abstract class LaserPrinter, each of which inherits from the printer. Specific classes represent different printer models and models and are inherited from either InkJetPrinter or LaserPrinter.

Each UserControl class in the graphical interface that the printer represents must have functions and functions specific to the type of printer. For example, an inkjet printer can have a display that shows the ink level, a certain model of a laser printer can have special functions that can be accessed from an additional button on the control, etc.

I see no better way to handle this than having a UserControl class inheritance hierarchy parallel to the Printer class inheritance hierarchy. Is there a better approach?

+3
source share
2 answers

, ? , , GUI, GUI . , , GUI, , UserControl.

+1

, , LaserPrinterControl InkJetPrinterControl, , PrinterControl. , PrinterControl.

, , PrinterControl.

+1

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


All Articles