When to Create an Abstraction in Code?
menu
telegram telegram
Contact me

When to create an abstraction in code?

I personally see only a few cases where abstractions make sense, namely:

  1. When we need to emphasize a business rule or a process.
  2. When we want to reduce the perceived complexity of the code.
  3. When we want to introduce a point of flexibility.
  4. When we want to group related things together to minimize the amount of work needed when making changes.

Sometimes developers create abstractions just to make the code look uniform. I’d argue against this. In my experience, it often leads to increased complexity and adds unnecessary layers that hinder understanding.

We also need to be very careful when introducing points of flexibility. Sometimes we end up adding complexity without any real business value — just to handle a case that may never occur.

If there’s an idea to create an abstraction that emphasizes an underlying technical concept but contradicts the clarity of the business logic, I’d prefer not to create it.

To sum up — if an abstraction brings real value to the code, I’d go for it. But if it’s just about following standards or “best practices,” I’d think twice.