Separate class versus method

Quick design question.

ClassA has a DoSomething (args) method

In DoSomething (), before he can actually do anything, he needs to do some preparatory work with args. I believe that this should be encapsulated in ClassA (as opposed to doing the preparatory work outside and passing it on), since nothing else should know that this preparatory work is required by DoSomething.

However, where the actual preparatory work code belongs, which makes me think.

The preparatory work in my specific example is to create a list of elements that satisfy a certain condition from args.

My guess is that I have to create a new ListOfStuff class that takes arguments in its constructor and puts this preparatory work here.

In terms of TDD, I think this is the right choice. Then we can unit test ListOfStuff so that our heart is happy. If we prepared the preparatory work for the private ClassA method, we would be able to indirectly test it using DoSomething () testing.

But is that too much? Since I adopt the TDD and DI approach, I have seen how many classes that I write multiply - should I worry?

That one.

+5
source share
6 answers

There are a couple of heuristics here.

  • , ? , doSomething(), ? , .
  • ? , .
  • doSomething() , ? , .

, . .

+4

, ? TDD . . -, , . . , . .

+4

. . , . , , .

, . .

, , , Strategy . ...

+2

, . ListOFStuff DoSomething , , , , .

, , ListOfStuff unit test, , , , > .

, !

+1

TDD DI , , , ?

- , . OO, .

, OO.

(imho).

+1

SoC , "" , , "" (, DRY). , , , private .

tvanfosson, SoC YAGNI. - , ( , ).

+1

All Articles