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](http://www.cheatsheetwarroom.com/fantasy-racing/nascar/free/rankings/drivers.aspx).
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);
BuildFootballCheatSheetContent(); // loads the UI based on data from the FootballCheatSheet class
BuildRacingSuppSheetContent(); // loads the UI based on data from the RacingCheatSheet class
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?
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.
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.
This topic is now closed. New replies are no longer allowed.