0

Don't seem to find a good explanation for this. Is it a bad practice to have e.g. a method on one layer call another method on the same layer?

4
  • Yes it can, Very common with application services. Commented Nov 8, 2023 at 10:44
  • So it is a good practice if I got an order service method with its own dependencies I can call a user service with some different dependencies ? Is there a documentation for this answer ? Commented Nov 8, 2023 at 10:52
  • wouldn't make much sense, if model can ever only talk to view-model and vice versa, would it? Of course you can have deep call-stacks within the same "layer". Commented Nov 8, 2023 at 11:16
  • You should include the exact scenario you have in the question with real examples. Architecture guidelines work best when these details are known. On a Higher level, As long as you follow SRP and good Encapsulation it should work. Commented Nov 8, 2023 at 12:37

1 Answer 1

3

In short - it depends.

The main concern is to prevent circular dependencies between same level components (which is not an issue when performing cross-layer calls for obvious reasons) i.e. ServiceA needs ServiceB which needs ServiceA. To prevent this I personally either introduce a "sub-layer" for shared functionality (something similar to the enterprise and application services separation in service oriented architecture) or move them into some kind of helper methods.

P.S.

  1. Sometimes it is ok to duplicate similar code (instead of moving it into some shared component/invoking existing one). The famous Don't repeat yourself (DRY) principle is quite often should be applied not to similar code but "business knowledge" - i.e. the same functionality/concept should be coded only once.

  2. Check out also - Does Vertical Slice Architecture Violate the DRY Principle?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.