lundi 18 mars 2019

refactor codes using visitor pattern

I am having problem when trying to refactor my codes. It is in a compiler like structure. The code structure is as follow. I have several target platform to generate my code like x86.

class Op
{
public:
  virtual doA(vector<int>& vec) = 0;
  virtual doB(unordered_map<int>& map) = 0;
};

---Directory x86----
class X86_Op_A: public Op 
{
public:
  virtual doA(vector<int>& vec){
      // genereate A type operator that do A under x86
  }
  virtual doB(unordered_map<int>& map){
     // genereate A type operator that do B under x86
  }
};

class X86_Op_B: public Op 

---Director arm---
class Arm_Op_A: public Op 
class Arm_Op_B: public Op


How can I refactor the code so that they look like vistor pattern and I can just give it my targetplatform and the operation I want to do.

I have tried thinking about writing an abstrct platform interface and implemented with different target planform. However, I still find it hard to write the code correctly. If I cannot use visitor pattern in this case, is there any way to refactor the code ?

Aucun commentaire:

Enregistrer un commentaire