What to abstract (and what not)

As a full-stack developer, I’ve come to appreciate clean code. I like things that are easy to follow. But over time, I’ve also learned that too much abstraction can hurt more than it helps.

I want to share my thoughts on when to abstract and when not to. This isn’t a strict set of rules, but it might help you make better decisions in your projects.

❓ What is abstraction?

In simple words, abstraction means hiding the details. It’s about creating reusable pieces so the code is more organized and flexible.

For example, in C# we might use interfaces, services to encapsulate a piece of logic, or like in React, we create components or hooks to encapsulate functionality.

When abstracton helps

  • You have copied the same logic a lot ot times. If you’re repeating code, it’s time to extract it into a method, service, or component. This makes your code cleaner and easier to maintain
  • You want to swap implementations later. Like maybe you’re using a local cache now but plan to switch to Redis later. A wrapper helps here
  • You’re building something shared. Like a common validation rule or API integration that gets reused

In these cases, abstraction helps keep your code DRY (Don’t Repeat Yourself) and makes it easier to change things later.

When to not abstract (yet)

This is where many of us (myself included) get carried away.

Here’s when you probably shouldn”t abstract yet and just keep things simple:

  • You only use the code in one place. No need to create a service or interface if a method will do
  • You’re not sure what will change. Premature abstraction often guesses wrong. It’s better to wait until the real need comes
  • It makes the code harder to read. If you have to jump through five files to see what’s happening… that’s worse than having it all in one place. 😅 It can be very confusing especially for new developers working in the project

Conclusion

Abstraction is a powerful tool, but it can also lead to complexity if used too early or too much.

Start simple. Refactor when the pattern becomes clear. And don’t be afraid to change your mind later.

Keep it clean. Keep it clear.