开发者

common services in layered architecture

I read in many books that in a layered architecture a layer should only use the services provided by the layers below it. The commonly used layers are in an enterprise application are:

  1. Presentation
  2. Business
  3. Persistence

This means services at business layer (that contain business logic) should access only access the services provided by the persistence layer.

I have a MessageService that sends messages to the users. Whenever there is a significant change in the state of an object, all the associated users must be notified about the change. This means that the Service at business layer that identified the change must send use MessageService to send messages. But messageService is itself at the business layer, hence no other service from the same layer should access it.

So how can we use MessageService without violating the architecture of开发者_如何学JAVA the code?


Presentation Layer(or the Top Layer) does not mean only UI, it can be anything that consumes the services in the system. ie, a Scheduled Job can be at the top layer(may be you don't want to name it as presentation layer).In your case I feel MessageService should be at top level as it consumes other services in the system. For example if you write a web service it should be above the service layer but you may be want it to be named differently.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜