7

I have a service that needs information implemented by another service in the same layer. Is it good practice for one service to take a dependency on another service in the same layer?

  • 2
    I would think that the best practice is to extract the part that's used in both web services, and have both services use that. – user16764 Mar 2 '14 at 19:14
14

Yes. I have seen architectural diagrams of SOA (Service Oriented Architecture) where exactly this happens. A service should be written in such a way that it doesn't care if user is calling it, a service in the 'same layer', or it is being combined into a composite service.

The Open Group SOA Reference Architecture diagram shows services calling services in the 'same layer': Figure 22-2 (http://pubs.opengroup.org/architecture/togaf91-doc/arch/chap22.html)

The Open Service Integration Maturity Model (OSIMM) is also a good diagram, the link is talking about IBM Process Server but Kim Clark and Brian Petrini give a really good explanation: Figure 1 (http://www.ibm.com/developerworks/websphere/library/techarticles/0904_clark/0904_clark.html)

| improve this answer | |
2

I use my services within each other. This way I am able to reuse my service methods, instead of copying algorithms all over the layer.

In my experience, one thing to be aware of is circular dependency.

  1. When initializing a service class, say in the constructor, initializing other service object fields may lead to never ending circular calling if the field also depends on the initializing service.

  2. When calling a method, a service method may call another service call and that may also call another service method which can lead to circular call again.

| improve this answer | |
-3

you could use "chain of responsibility" design pattern to achieve this.

http://www.blackwasp.co.uk/ChainOfResponsibility.aspx

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.