Inheritance or Interface or ??
I have many types of objects that will implement many "style" properties (i.e. fonts, colors, etc) The catch is that each of these objects will implement anywhere from 1 to x number of these style properties. What is the best way to architect this design? For example if I have one base class that contains ALL the style properties and then have the other classes inherit the base class, the problem there is that there is no way to "hide" certain style properties that do not pertain to specific objects (i.e. hide font properties for image objects). This isn't a problem as much as an inconvienence, but it would be great to "hide" the inapplicable properties. One way to get that effect is to use interfaces, where each interface only implements the appropriate properties. This seems to work, but I have heard that this is not good practice; are there any other suggestions as this seems like it should be doable?
Note: The one reason I really don't want to do all separate classes is that if more properties are added in the future, that would mean that I would have to go through and add each property definition to each of the classes as opposed to just defining it once and implementing it where applicable.
Any help would be great, thanks!
Re: Inheritance or Interface or ??
Just a suggestion Clark. Have you tried inheriting and then overriding the properties you want to hide as private?
Re: Inheritance or Interface or ??
No, but not a bad idea...kindof a workaround, but not bad if it works.
Re: Inheritance or Interface or ??
What kind of code are you putting in your properties? Depending on what you're doing, one thing you could do is have a StyleFactory class. That way all the style behavior would be encapsulated in one class, and the factory could return different things based, on say, a config file setting. For example (pseudo code),
textBox1.BackColor = StyleFactory.TextBoxBackColor
Just a thought,
Buoy