Currently I have two different (A,B) classes which basically share common logic but also one of them (let’s say class A) have special additional logic. Class A pretty much contains B’s logic. I want to unite them into one base class.I thought about doing one base class which will contain all the logic, and have two sub classes which will define a flag whether or not should we execute the special logic I mentioned and then I can check this in the base class. I guess I can also have a base class containing B’s logic (the more specific one) and then extend it to another sub class which will implement the special logic. Wanted to hear pros and cons or any other ideas that might come up. Thanks !

  • $\begingroup$ Create a base class with all of the common logic, and from it derive the two additional classes A and B. If B's logic is entirely contained in A as well, consider just making A inherit from B instead of adding a new base class. $\endgroup$
    – nir shahar
    Apr 25 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.