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 [URL=“http://www.cheatsheetwarroom.com/fantasy-football/nfl/free/rankings/offense/quarterbacks.aspx”]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.
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?