Search code examples
winformsdesign-patternsgridviewseparation-of-concernslaw-of-demeter

How can I keep separation of concerns when using a grid in the presentation layer (esp. .NET)?


In a three-tier model (presentation-business-data access layers), I can consistently keep my lower layers agnostic of the upper layers. For example my data access layer never knows how it is presented or what busines rules are operated on it. My business rules are agnostic of how they're presented.

But I must pray to Demeter for forgiveness or at least ask fellow Stackoverflow members for advice on one thing: How do you present a "Table" to the user without referencing the Data Access object in the Presentation Layer? Time and again, I find myself referencing a ADO.NET DataTable in a GridView object. Currently I'm using third-party tools in both layers. The Table is from OpenLink's OpenComponents Table object; the grid is an Infragistics UltraGrid (Windows platform). Yet I'm guilty of the same infraction.

edit: I am most especially interested in how this may be done with WinForm 3.5 .NET. Note my comments below: I believe the link in the comment is what I should have done, but I was hoping that I wouldn't have to get too fancy with domain objects. I don't want to be accused of over-designing. Is this a good balance?


Solution

  • Instead of using a datatype that represents a table, I'd use a Data Transfer Object. This would be an object that represents the logical structure of the data. It would contain nothing but data.

    In this case, I'd define a DTO for my "data row" type, and then use a List<RowDTO> as the type I'd pass to the grid.