-2

I cant quite think of a good way to achieve the following:

  • I have a base window class SlimWindow which inherits from some 3rd party window (Devexpress)
  • I have a base dialog window SlimDialogWindow which inherits from SlimWindow
  • I have a base window for certain class of windows ModuleWindow which inherits from SlimWindow
  • I now need to have 2 sets of windows - one are that behave the same as SlimDialogWindow and another that behave like both - SlimDialogWindow and ModuleWindow. Lets say currently there are 10 windows inherit from SlimDialogWindow - I need to split them to 6 to behave like SlimDialogWindow + ModuleWindow and 4 to behave like SlimDialogWindow

SlimDialogWindow + ModuleWindow vs pure SlimDialogWindow - pure dialog is just a window with OK/Cancel buttons and some other functionality, ModuleWindow - sets some properties - e.g. remove it from task bar and alt-tab plus some other stuff.

How to make it work?

Boppity Bop
  • 9,613
  • 13
  • 72
  • 151

1 Answers1

1

I think I would go with either of these approaches:

  1. Create 2 versions of SlimDialogWindow. One that inherits SlimWindow, and another SlimModuleDialogWindow which inherits ModuleWindow.
    That'll give you the versatility to use either one according to the scenario. Of course I don't know how much code you have in SlimDialogWindow. If it's just xaml, it could be solved with a template to be used in both. For procedural code, maybe you could export it to a common class.

or use this approach:

  1. Make ModuleWindow an optional extension of SlimWindow. You said it affects some properties. So maybe add a flag in the SlimWindow constructor - IsModule, to set the changed properties.
    If you want a single class for both scenarios, I don't think you have many options besides combining both.
    Thinking about it. Maybe you can have ModuleWindow as a single class, with a flag to disable its features. It would allow you to separate the classes, but it still amounts to the same thing.

Hope this helps

CKII
  • 1,439
  • 14
  • 26
  • 1
    yeah I did what you describe in #1 - just copy/pasted it. btw - xaml does not enter picture in the whole thing because WPF doesnt have visual inheritance. You cannot inherit a control/window with XAML. all the inheritance described in the question are just .cs files... Ill try your #2 one day.. thanks – Boppity Bop Aug 29 '23 at 15:47