jeudi 9 mars 2017

How to refactor this kind of situation

I am implementing an algorithm with several computation modes in C++, and now I found the my class is too huge and difficult to maintain, so I want to apply some design pattern to refactor it. But I have little experience in software engineering. Thank you so much if I can get some idea or hints about which design pattern to use and how to deal with itenter image description here

My algorithm runs like the graph above. There are two issues.

  1. For each function (f1(),f2(),f3(),f3S()) I have three different implementation. So now I have f1a(),f1b(),f1c(),f2a(),f2b(),f2c(),f3a().... totally 12 functions in the header file.

  2. f3S() can substitute f2()+f3(), so I call the two way quick mode and normal mode

I was thinking bridge pattern , however, the a,b,c implementation and quick,normal mode can not totally vary independent. I still need implementation of every f1a(),f1b()... not f1(),f2().. and a(),b().. then combine them.

also I am thinking the structure like this (some parts are omitted) enter image description here

But if I want to do dynamic binding-- class1 c = new QuickMode()(I hope I used the right term) , I need to put abstract virtual function f2(),f3(),f3S() in Class1, but if the object is a Quick Mode one, but I call f2()it is certainly wrong, but it actually have a pointer of it.

I am sorry for the long post, I have little experience of OO programming and it had already bothered me for a few days. Really thankful if someone can give me some ideas.

Aucun commentaire:

Enregistrer un commentaire