views:

17

answers:

1

I want to send back formatted messages from my domain, For example things like: (Bear with me this is not a real example, its just to illustrate my point)

Hello Mr user, you cannot perform that task because:

  1. reason 1
  2. reason 2
  3. reason 3

I also want to show colors.

Right now I am sending it from the domain already marked up with HTML.

This seems wrong to me. Because if I want to re-use that domain with a different front end, that may not be HTML aware, it will require different formatting and/or markup.

How can I design this so that my messages from the domain intended to be displayed on the user's screen can be markup ignorant?

+2  A: 

For something really simple you could do something like this:

class DomainMessage
{
    public string Message { get; set; }
    public Color ForeColor { get; set; }
    public bool IsError { get; set; }
}

Or you could use the decorator pattern and create a message that way. You could then create a DomainMessageWriter that takes a domain message and spits out the right markup (ie HtmlDomainMessageWriter, RtfDomainMessageWriter etc).

HTH

TheCloudlessSky
I like the idea of a domain message writer, it could even be swapped out using IOC for a different implementation if used with a different front end.
Roberto Sebestyen
@Roberto - Yeah exactly. You could also "apply" different styles to the `DomainMessage`. You could also have many other types of `DomainMessage`s too.
TheCloudlessSky