Discussion about this post

User's avatar
Denis Čahuk's avatar

No. Keep using the if-else chain or match.

This is not subtype polymorphism.

Subtype polymorphism requires differences of behavior. Your examples only have differences in data (the country's rate).

There is no difference in behavior in your examples.

A better example would be using a static table for Country -> Rate where calculations are simple and use the same function to calculate _income * rate_

Edit: I wanted to clarify. I better example to use for the non-polymorphic behavior would be to use map. A better example for the polymorphic behavior: 2 countries where the formulas are vastly different, or instances where one country's tax rate is determined by country alone, while another is determined by country, state and the person's previous residency in the last year.

Expand full comment
Dave Liu's avatar

OOP is a damn plague. Constantly misused, and a quintessential example of over-engineering. This is why Python is the most popular language.

Expand full comment
1 more comment...

No posts