I'm trying to find the best design approach to handle a design change in a new project I'm working on.

At the moment, the flow runs and makes some calculations based on a parameter which is used.

Now, different parameters needs to be added and a new flow would have to be run for each of the other params as well.

Just to emphasize, the flow of the logic doesn't change, it remains the same.

However, since now the flow needs to be run not only for one parameter but for others, and potentially more (just assuming) the output would change for each flow.

I want to refactor it in such a way that another change in the future, won't cause a major change.


Ok, so I added some contrived code which represents the code flow.

var service = new Service();


class Service {

public Start() {
     var manager = new LogicManager();

class LogicManager() {

    public calculate(){
        var dataProvider = new DataProvider();

class DataProvider
    public getData(int filter) {
        // common logic

        // seperate logic per filter

The filter itself is used for a query against a data source.

Inside DataProvider, I managed to extract the common code regardless of the param being passed to different methods. which leaves me with the logic which needs to be executed per filter.

Now, I can create in the provider, a dictionary/array an iterate over it in a simple loop, but I'm not sure if that's is the best way.

@candied_orange: What you are saying is what I was thinking about - separate what is changing - which is the param. However, I can't find a suitable pattern for it.

  • 3
    And class inheritance and reusing the stuff from the base class doesn't solve your issue? Can you give a more concrete example of what you already have please? – πάντα ῥεῖ Feb 15 at 16:11
  • 2
    This is certainly an interesting question. I fear however that I did not grasp what you want to achieve. Could you provide an example ? – Christophe Feb 15 at 16:28
  • 1
    Are the parameters different types? If they're all floats, can you just put the function in a loop and run it for each value? Please explain more clearly what the problem is because it's unclear. – Gimme the 411 Feb 15 at 17:19
  • Very unclear, if the flow doesn't change, what do the parameters do? Provide a real-world scenario or sample code. Also, what language are you coding in? – Martin K Feb 15 at 21:50

Separate the things that change from things that stay the same.

Express your “logic flow” is some way that hides the details of these changing parameters. Put those details behind abstractions and not only will you be able to reuse this expression of the logic. You’ll also create a place free of unneeded details that will help others understand the logic flow.

Two things make this difficult. The abstractions can’t leek details and you have to correctly predict what will and won’t change.

I deal with the first issue by focusing on the using code first. I deal with the second issue by waiting until change is actually happening and dealing with it then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.