Open Closed Principle confusion

In the case of some logic involving a class. Eg. There maybe an Account class and we calculate the interest differently depending on the type of account with if else. ( eg. if Regular calc this way, else Saving calc that way) . This is undesirable.

With Open Closed Principle, we were taught to turn the original class ( Account ) into an interface, and then introduce derived classes which have their own versions of calcInterest . Now that calcInterest method is implemented in derived classes, we don't need to update existing code logic to accomodate for any new Account type everytime we introduce a new derived Account class.

However, my question is that, when we create the derived class. Wouldn't there still be if else loop to determine which type of derived class we consturct, doesn't that go against open closed principle?
Was this page helpful?