开发者

How can I make messages (coming from the domain) format/markup ignorant?

I want to send back formatted messages fr开发者_如何转开发om 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜