Interfaces, inheritance and window forms in C #
I have a design question. When writing an application where there are several components that share some attributes and differ from each other both from the point of view of the GUI (window forms) and from the reverse side, how can one theoretically approach this?
For example, I have an application where I have 4 different product types. Forms for entering product details all share 3 different fields. So far simple is to have a base class and then infer 4 forms from that base class. However, let's say 2 products have a specific behavior that is ONLY for both of them. Of course, I could have an interface that defines methods and then these two forms of product input implement that interface, but since the interface does not provide a default implementation, wouldn't that be a departure from that? Since I would have to provide an implementation in each class, and if it is exactly the same, it will be code repetition.
I could, of course, put this method in a base class and get 2 forms out of it. If my shapes share more than one common element and don't share other elements, what would be the safest, most logical way to present this without having to pluck my hair out?
a source to share
Why don't you get 2 unrelated classes directly from your base class, and then create a new class with common functionality and get from the base class, and the remaining two classes inherit from this new class?
BaseClass
CommonClass : BaseClass
ClassA : BaseClass
ClassB : BaseClass
ClassC : CommonClass
ClassD : CommonClass
a source to share
It's hard to tell without any specific layout. in general, another, often more flexible, form of reuse is doing composition instead of inheritance. Actually the control hierarchy shows how strong the composition can go. Perhaps you can split the parts of your UI into custom controls that are assembled based on the specific product layout you are after
a source to share