We’re rewarding the question askers & reputations are being recalculated! Read more.
    Tweeted twitter.com/StackSoftEng/status/901243465924739072
2 edited tags
| link
1
source | link

Is there any technique to help in deciding where a certain functionality belongs?

In Object Oriented Programming, since we use classes and methods in these classes, when we are going to implement a certain functionality we must decide where it belongs, in other words, on which class it belongs.

This raises questions like: "should I create a new class and add this there" or "should I add this to one existing class".

The main things I'm aware of are: (i) there is no right way to do it, there are many possible ways that will end up working and (ii) implementing one way and later refactoring is usual.

Actually, when following up the develoment of ASP.NET Core on Github I saw some functionality from time to time move from here to there.

My issue is the starting point: I'm going to implement a new functionality, I know the logic that needs to be coded, I know the business rules, I just don't know where to place it.

I know some theory like SOLID and a little bit of DDD. I like DDD because it gives categories of classes like "entities", "value objects", "repositories", "domain services", so it seems to give a starting point.

My question is how to use this all in practice. Is there some technique that helps deciding where (on which class) a certain logic belongs? What is the way of thinking that I should adopt? My question is really this: how should I think, what is the line of thought I must follow, to make this decision to get started (obviously not make a choice once and for all, as this can change, but at least get started)?