3

I'm currently at the design phase of my program (hence no code). It will be written in WPF in C# using MVVM principles.

I'm going to have a multifunctional Drag & Drop control, that will act similairly to a Facebook's Post on the Wall.

To make this clear, imagine it could be a calendar event, an important note, a product update etc.

That means they will differ in models that they will be based on.

What do you think would be the most SOLID approach to building such a control? What I came up with:

  1. Have a single control object, that based on the "type" that it is created as, inherits different models. (though I'm not entirely sure how I will manage to do that yet.
  2. Have different controls for each "type" that all inherit from a base control class and extend the basic functionality.
  3. Any other solution, that could be even better?
1

I try to follow the maxim "favor composition over inheritance." In other words instead of baking in behavior at compile time, wire it up at runtime. This follows the "Open/Closed Principle" of SOLID, which states that code should be open to extension, but closed to modification. In other words, you should strive to design your code in a manner that you can extend its behavior (with abilities like drag-and-drop) without having to modify the existing source code (by modifying the base class to add drag-and-drop).

IoC containers are useful for "wiring objects up" at runtime without having to change any code.

  • UI hierarchies are typically an exception to the "favor composition over inheritance" rule. They don't require the flexibility that composition provides in a business logic context. – Robert Harvey Nov 30 '16 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.