1

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 the code?

Amit Khanna
  • 489
  • 4
  • 16
  • Amit, What do you mean by 'all the associated users'? – Alex Barnes Sep 19 '11 at 15:23
  • I mean all the users who are interested in any changes in the state of an object. For example, a new user is added in a group so all group members must be notified about this using MessageService. – Amit Khanna Sep 19 '11 at 16:46
  • Are the changes to the object made via the presentation later? If so why not just have the business layer pass back the changes to the presentation layer and then invoke the messaging service when the persistence work is completed. – Alex Barnes Sep 20 '11 at 09:29
  • There can be multiple presentation layers, using JSP, GWT or webservices, so if i keep message service at the presentation layer it means that I have to replicate the logic for sending message. – Amit Khanna Sep 20 '11 at 10:00

1 Answers1

0

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.

ManuPK
  • 11,623
  • 10
  • 57
  • 76
  • Thanks for the reply. I think it should not be part of presentation layer because there can be multiple presentation layers. If MessageService is added to presentation layer it must be replicated, which I don't think is a good solution. – Amit Khanna Sep 19 '11 at 16:51