I have 3 classes: Service, Client and Mess (which I should somehow refactor).
Class Service {
void servicemethod(int a, int b, int c)
{
//does something with params a, b and c
}
}
I have the client class which calls two methods from the same Mess
Class Client {
main()
{
Mess.setABC(x)
Mess.callintermediatemethod(int x)
}
}
The Mess class does nothing but reads params a, b and c, which are values associated with key "x" in a file, and calls Service.servicemethod(a, b, c)
:
Class Mess {
static void setABC(int x)
{
//sets static params a, b and c with values read from json file that has x as its key
}
void callIntermediatemethod(x)
{
Service.servicemethod(a, b, c);
//here x parameter is not even necessary since it already knows what A, B and C are.
}
}
Clearly, the Mess class does two things. Sets static variables after reading x and calls service method with the values stored, taking a dummy parameter. This clearly is bad design. But if I decide to do away with mess, how do I set the parameters a, b, c given the variable x? Should I associate them with an object? Decorate them? Use a builder pattern or a dependency injection? How to clean up Mess and make Client class directly call the service method without having to pass through Mess?
Aucun commentaire:
Enregistrer un commentaire