mercredi 13 novembre 2019

Designing implementations with minimal change

Theoretical discussion

I have a code base with an interface and an implementation . Lets call the implementation as implA spread across multiple .h and .cpp files . Now I am required to have an alternate implementation of the interface . However 98% of the code is same . Now multiple options exists .

option 1 ) make changes in implA and change code based on a flag and under some flag implB related changes come into affect . Its bad because my code will have a lot of if and else and things will be cluttered and hard to understand .

option 2) I have to copy paste entire implA to implB and then make changes in implB. This way both interfaces are seperate but then tere is a design principle . Dont repeat yourself . If tomorrow there is a bug in implA , i will have to remember and change part in implB area as well .

option 3) Take out common areas into some class . use that as aggregation in these 2 impls. This seems plausible and OK but then i am changing implA as well when there is no need to touch implA . I should not be touching files and implementations which are not required to be changed

please suggest

Aucun commentaire:

Enregistrer un commentaire