2

I have to design for a bunch of user control types, each of which share some common properties but some of which have special unique properties.

For example, the common properties across all the controls would be title, caption, field length, etc. But for specific types like Dropdown, FileUpload, apart from common properties, they have their unique set of properties like list items, destination folder path, etc.

I have around 20 controls and have to design for extensibility as well. The only thing which changes across the various types is their properties. Nothing else. I could use simple inheritance. But, is that the right way, leading to having 20+ concrete types and keep increasing them over time? Or is there any specific pattern that would be advisable for this use case?

  • 2
    Inheritance is generally the way this is done in UI control hierarchies. In fact, it's the one area of computing where inheritance always seems to make sense. – Robert Harvey Jun 3 '16 at 17:30
1

I'd go to simple inheritance, but maybe you can group some classes in subsets like visual studio does. For instance, you got Control as the parent class with the core properties and behavior for all controls: caption, location, etc.; in the other hand there's a class that inherits Control that acts as a parent for SaveFileDialog and OpenFileDialog, since those also have common characteristics.

I'd go pretty much the same way.

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.