+4  A: 

Have you heard of Martin Fowler?

Separating User Interface Code

Anyway, if he wants to go further in that direction of adding render methods to his data controls, have him look at "loose coupling". It's okay to create some generic type of interface that gets him halfway there, but the UI component should take it the rest of the way.

Marcus Adams
A: 

This boils down to functional vs. non-functional responsibilities. What the data structure does and how it's visualized are two completely separate things -- essentially the root of the MVC pattern.

There's also a notion of circular dependencies here. Since the UI must know about the data structures, if you allow the data structures to then depend on the UI, you've got yourself a nice little ball of mud.

Shaggy Frog
And by functional you mean interacting with the data with the UI, and non-functional being; just a container for the data, like the result-set...right?
leeand00
Functional as in "what something does", non-functional as in "how something looks". In MVC, the "what something does" is the Model, and "how something looks" is the visualization of the model, the View.
Shaggy Frog
A: 

Generally on the point of decoupling:

  1. Not only can there be different components of the UI rendering the same data structure. You may even have completely different UIs (Web, Desktop Application, ...) Now of course, you could subclass Person with WebPerson and DesktopPerson (this already sounds wrong, doesn't it? The naming is simply not about the kind of Person - it's about something else).

  2. Each UI could work on different kinds of Persons, e.g. Teacher and Student. So we get WebPerson, WebTeacher, WebStudent, DesktopPerson, DesktopTeacher and DesktopStudent.

Now let's say, WebPerson defines the method "drawAddressFields()" to draw a web version of the address fields. But since WebTeacher has to derive from Teacher to use the additional data field "salary" (and let's assume single inheritance), it must implement "drawAddressFields()" once again!

So maybe the argument of "this will cause much more work" will help to create some motivation :-)

BTW, it will automatically lead to creating some delegate that implements the code of drawAddressField(), which will then evolve to creating a component that does the drawing separately from the data structure.

Chris Lercher