Consider you have a GravityLogic and a WeakForceLogic class. In themselves both provides tons of business logic. Now you want to create interactions between those which produce a complete different set of result. Would you rather create GravityWeakForceInteractionLogic class if this is going to generate a lot of new algorithms or put the new logic elsewhere (for example Helper classes) ?

I'm struggling a lot in organizing such intermediary business logic code on the backend side. The gravity and weak force logic are just examples. What I'm trying to avoid is having "linking" business logic between backend objects in the upper layers. I also want to provide a more robust API for our frontend. I just find myself always wondering where to put these algorithms.

This question is for any object oriented language. I know that each case could call for its own place but for now, let's assume that this linking logic is complicated and would bloat the original classes it is trying to connect in some way and extract meaningful information.

  • It's too hard to answer this question without a little more information on what the XXX and YYY classes are. The answer depends on what those classes are doing. Sep 7, 2018 at 17:25
  • Physics, eh? The name "GravityLogic" is explanatory enough for me (not a physics expert), but I'm a little fuzzy on what "WeakForceLogic" does. Can you elaborate? Sep 7, 2018 at 17:39
  • Is this what you mean by WeakForce: livescience.com/49254-weak-force.html Sep 7, 2018 at 17:40
  • 1
    It doesn't matter at all. All there is to know is that both classes are instantiable and contains plenty of algorithms. They are part of a backend that provides services for a presentation layer. I don't want to add the interaction logic in the presentation layer. I want it in the backend. Is it better with a new service completely or agregate this logic elsewhere. Could be fruits or biometric logics, it doesn't matter. Sep 7, 2018 at 17:57
  • Maybe a parent class with instances of both of the lower classes and it's own parent logic that works on/with the instances of the other classes? Sep 7, 2018 at 18:01

1 Answer 1


Since our problem domain seems to be physics, I'm going to make a few assumptions in my answer:

  1. GravityLogic contains methods that encapsulate mathematical algorithms for solving gravity problems

  2. WeakForceLogic is a class with algorithms for Weak Force from particle physics.

Understanding the problem domain is the key here.

If logic requires gravity and weak force, where does it go?

How does gravity and weak force relate to each other in physics? That's the question to answer. So, the places to put this coordination logic would be:

  • The interaction between the two may have a term or idea in physics, which becomes a new class that performs these coordinating calculations.

  • Expose more methods on GravityLogic or WeakForceLogic that takes the other class as an argument.

  • A "use case" class that handles instances of these two classes to perform larger calculations.

  • Great answer. I think it pretty much sums up what I'm looking for. Sep 7, 2018 at 18:35
  • Very well explained, and the generic reasoning can be applied to any other cases with complex interacting logic. +1
    – Christophe
    Sep 8, 2018 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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