Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • I depend on external services. Each one need to be call on a specific service. It is related to our customer internal architecture/information system. Even if I do not create a doStuffWithFoo, I will need to process a collection of Foo so in any case the switch will be done somewhere. Commented Mar 22, 2022 at 10:27
  • I know polymorphism can do it for me at run time, but only if I place my business logic inside my object. If I want to place it outside, then I do procedural programing and polymorphism do not apply. It is what I understood by reading about Anaemic vs Rich domain model thanks to @Philip Kendall reply. I also understand having 2 functions doing the same thing but with different implementations seems to be irrelevant. Actually it is but it is not on my scope, I need to deal with it :/ Commented Mar 22, 2022 at 11:12
  • Ok, I think I see your problem and may be able give you an example how to approach this. Commented Mar 22, 2022 at 11:31
  • 3
    Where do you decide which of the instances (Bar, Baz) to create? If a conditional check should be anywhere, it should be confined there. What's the reason you didn't implement doStuff() directly in Bar and Baz? "doStuff is business logic and not class behavior" - what do you mean? High-level class behavior (which is different from implementation details of a function) should be an expression of the business logic, that's the whole point. Commented Mar 23, 2022 at 0:22
  • 1
    To me, this hinges on the details of the actual case -- in what ways are the operations in doStuff the same/different between Bar/Baz instances? What is the Foo interface? etc. IMHO, Just thinking about the problem in the abstract won't lead to a conclusion. Commented Mar 23, 2022 at 17:32