I’m working on building my own base user interface classes. On them, I want them to all have similar ‘common’ properties and methods. I could define an interface class, but interface appears to only allow abstract methods, and no properties.
I don’t want to copy the otherwise exact same code to each class, but not sure how to implement… Ex: I want this common stuff to be applicable to Buttons, Textbox, Checkbox, Listbox, etc user controls.
Suggestions???
I myself come from a C++-background where multi-inheritance is allowed and used extensibly, so I often ran into the same problems as you. The first thing you need to do is to read up on mix-ins – here you’ll prolly notice that you’ve used them yourself all along, without ever naming them. Second step is to start to recognize your mixins whenever you need them, and you’ll often find out that you might as well use them via composition. Third step is to implement them using composition… Yes, i hate this too, but there’s no way around it if you wanna go .NET (or Java or…) 🙂
What you should use inheritence for is not for your mixins, but for stuff that actually identifies your items. I recommend looking at the .NET hierachy for some of the common controls (textbox and the likes) to get some inspiration.
Good luck