SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru pinch's Avatar
    Join Date
    Mar 2005
    Posts
    688
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Coding to an Interface in Web App

    In my application I have various objects of different types, for instance Football Cheat Sheets, Racing Cheat Sheets, etc. When displaying these items in the UI, the layout is generally similar but the data may be slightly different. You can see the difference between racing templates and football templates.

    To build user interface components, I generally pass the ID of the object (of a "FootballCheatSheet" or "RacingCheatSheet" in this example) to the user control, then use logic in the user control to determine the sheet type and ultimately call 2 different methods for loading the content based on the specific requirements.

    Code:
        void BuildControlContent(int cheatSheetID)
        {
          Globals.SheetTypes sheetType = this.GetSheetType(cheatSheetID);
          switch (sheetType)
          {
            case Globals.SheetTypes.FOOTBALL_SHEET:
              BuildFootballCheatSheetContent();  // loads the UI based on data from the FootballCheatSheet class
              break;
            case Globals.SheetTypes.RACING_SHEET:
              BuildRacingSuppSheetContent();  // loads the UI based on data from the RacingCheatSheet class
              break;
          }
        }
    Since "FootballCheatSheet" and "RacingCheatSheet" inherit from "CheatSheet", I'm thinking I should pass-in a CheatSheet interface and call the passed object's BuildCheatSheetContent() method is a business layer or something similar. However, because the point of these methods is to populate UI components, I'm not sure this can be done in a business layer.

    Is there a better OOP or .NET way to do this?

  2. #2
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    Sorry for the late response.

    I know it's more work, but honestly, but what I would do is make two controls. But, the way you're doing it is ok for now. The problem is that later, as you add more 'types', your one control will grow to an unmanagable size. I would suggest looking at MVC, as it has much better separation of logic and presentation.

    Hope that helps.

  3. #3
    SitePoint Guru pinch's Avatar
    Join Date
    Mar 2005
    Posts
    688
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That makes sense. I'm re-factoring things and want to make the application as flexible as possible, but trying to apply these OOP concepts when binding data to user interface elements is a little tricky.


Bookmarks

Posting Permissions

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