lundi 13 août 2018

Design pattern for multiples methods using same argument

I have this class on which I have a method and will return a map, using dozens of methods inside it using the same arguments.

My class has thousand of lines and it will increase even more.

I can create several classes and inside create methods, but I´m asking if there is a special design for this scenario

Actual Scenario:

public Map<String, Object> transformMapOnAnotherMap(Map<String, Object> firstMap) {

   Map<String, Object> lastMap = new HashMap<String, Object>(firstMap);

   lastMap = do1(firstMap, lastMap);

   lastMap = do2(firstMap, lastMap);

   lastMap = do3(firstMap, lastMap);

   lastMap = do4(firstMap, lastMap);

   //more 20 methods

   return lastMap;

}

Try without design:

public Map<String, Object> transformMapOnAnotherMap(Map<String, Object> firstMap) {

    Map<String, Object> lastMap = new HashMap<String, Object>(firstMap);

    Do1 do1 = new Do1();
    lastMap = do1.do1(firstMap, lastMap);

    Do2 do2 = new Do2();
    lastMap = do2.do2(firstMap, lastMap);

    // more 20 methods

    return lastMap;

}

Aucun commentaire:

Enregistrer un commentaire