mardi 16 janvier 2018

Best way to add pattern strategy needing different parameters

I have a class

class A {
    int a,b,c,d;
    void caller(std::string s);   
    void func1();    
    void func2();    
    void func3();
}

and caller is like :

void caller(std:::string s) {
if (s == "1")
    func1();
else if (s == "2")
    func2();
else if (s == "3")
   func3();
}

But those functions shouldn't be in that main class. I want to transform it into a pattern strategy, so that would only be a call to A.B.func(). The thing is, for instance func1 only needs a,b,c, func2 only needs b,d ... For now they access the parameters beeing part of the class. Is there a convenient way to do pattern strategy with that context ? (I mean, without calling each function with (a,b,c,d) and not using all of the parameters).

Aucun commentaire:

Enregistrer un commentaire