Class design and object orientation RRS feed

  • Question

  • Just a quick query about my class design and my web app....

    I have a base class


    and two widgets that inherit




    My question is, each widget needs to be added to a category, which for the most part is pretty fixed
    e.g.Categories: Basic, BasicPlus, Standard, Deluxe, Professional, Advanced, Superb and Fabulous.

    I have a webpage called category.aspx that needs to list all of the categories in the application, when the user clicks the category name, it then needs shows all of the widgets in that category.  Simple stuff, but I just want to make this O-O and 3 tiered as possible.

    The database tables

    widget ---< widgetcategories >----- categories
    just a standard link table, as each category, could potentially be added to a number of categories (although this won't happen very often)

    So, do I create another class called category and do it that way, add the category as a field in the base class? I can provide a little diagram if that will help?

    any help appreciated

    Tuesday, March 10, 2009 10:28 AM

All replies

  • Sounds like you need categories class like the following...


    Is that what you want?

    Also, if you have a database already mapped out, could you use an ORM like nHibernate or EntityFramework to do this dirty work for you?

    { Gaja; }
    Pl mark if answer solves your problem | Visit for .net ref Arch
    Tuesday, March 10, 2009 7:29 PM
  • I'll take a look at the frameworks, but I wanted to nail this myself manually, to get a handle on things.

    I'm not sure what you mean in your code though?

    Are you saying I create a class called Categories, which then contains the other widgets?
    • Proposed as answer by zoff fab Tuesday, March 10, 2009 9:06 PM
    • Unproposed as answer by andrew_vs2005_c_ Tuesday, March 10, 2009 10:15 PM
    Tuesday, March 10, 2009 8:35 PM
  • Hi Andrew,

    Thanks for sharing the scenario. I think you are right and category could be made a property of the base widget class. But you have to keep it of type List<string>.  Because a widget can belong to multiple categories and type List will help during search.

    Hope this will help.
    Wednesday, March 11, 2009 12:59 AM