Results 1 to 4 of 4

Thread: Inheritance or Interface or ??

  1. #1

    Thread Starter
    Fanatic Member clarkgriswald's Avatar
    Join Date
    Feb 2000
    Location
    USA
    Posts
    799

    Exclamation 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!

  2. #2
    Lively Member Shardox's Avatar
    Join Date
    Nov 2006
    Location
    Barcelona, Spain
    Posts
    123

    Re: Inheritance or Interface or ??

    Just a suggestion Clark. Have you tried inheriting and then overriding the properties you want to hide as private?

  3. #3

    Thread Starter
    Fanatic Member clarkgriswald's Avatar
    Join Date
    Feb 2000
    Location
    USA
    Posts
    799

    Exclamation Re: Inheritance or Interface or ??

    No, but not a bad idea...kindof a workaround, but not bad if it works.

  4. #4
    Lively Member
    Join Date
    Oct 2006
    Posts
    71

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width