I have a simple Address object in my domain that has a ToString() method that returns the address like this:
123 Test Ave
Appt 1A
Spokane, WA 99201
We will be displaying this in a webpage on several different occasions so it makes senses to add the functionality somewhere to display the address with Html formatting, but when I want to add a ToStringHtmlFormat() to my domain class it begins to start to smell funny.
I am probably being a bit picky, but where or how do you suggest accomplishing this to keep my domain class free of any Html stuff?
You could have an HTMLWriter that is able to “Visit” the domain classes and print out the stuff. Your domain classes then need an Accept method to accept the Visitor (Visitor pattern).
In terms of flexibility and maintainability though I would go for some templating engine that contains your HTML and the access to those properties that you want printed out. Often more complex sites will also introduce something called a ViewModel, which prepares the data to be displayed in a way that is easily accessible by UI HTML Engines.