What are (if any)the implied assumptions or restrictions and the differences of designing like:
A) this:
class SampleClass1
{
IWorker workerA;
IWorker workerB;
void setWorkerA(IWorker w);
void setWorkerB(IWorker w);
WorkResult doWork();
}
B) versus this:
class SampleClass2
{
WorkResult doWork(IWorker workerA, IWorker workerB);
}
I know it depends on the specific project but what if the above class is a part of a small framework? The first Class is able to maintain state and separate the steps more naturaly but Second class ensures "real time communication" with the external caller more naturaly since Worker are passed each time doWork() is called.
Are there any recommended usages or generic practices that guide the choice between the two above ways? Thanks.