in Coding

Don’t depend on details – an example

I recently read Clean Architecture by Robert C. Martin. The book gives a simple advice: don’t depend on details! For Uncle Bob details are things like the database or message broker. Your architecture shouldn’t depend on the actual used implementation of those details. Whether your are using Oracle, MySQL or DynamoDB, whether it’s ActiveMQ, Kinesis or an in-memory Guava event bus – your architecture shouldn’t be affected.

Don’t depending on details has some advantages:

  • As you don’t depend on the actual implementation, you can change it. You can decide to use DynamoDB instead of MySQL because you want to migrate to AWS.
  • You can test your code more easily. As you don’t depend on an actual implementation you can use mocks or an in-memory variant for testing or local development.
  • You can change your mind. Being independent gives you the freedom to change things in the future.

Today I updated one of my demo projects on GitHub. I replaced Guava’s event bus with Spring’s own event bus implementation. Both implementations do exactly the same – they send events. However, my code had a strong dependency to Guava. Each and every listener imported an annotation from the Guava library. A detail on which I depended.

The result was this pull request:


Although the implementation of Guava and Spring are doing exactly the same, I needed to change 18 files. There were no tests and it’s just a small and stupid demo project – still, I needed to touch 18 files in order to switch from one in-memory message broker to another. This shouldn’t be the case! Don’t depend on details!

Best regards,



Write a Comment


  1. Hello Thomas,
    Thank you for your post.

    Have you implemented any improvement?
    Do you have any idea, how could you do it better to avoid this “not depending on details”?

    Actually, you haven’t changed any code, only metadata (annotations) :).
    If instead annotations you had used good old xml configuration, you would had to change only one xml file:)

    I don’t know if guava allows replacing annotations with xml configuration, similarly I don’t know if it’s possible with spring at least without implementing some spring specific interface. Assuming it were possible, would you prefer it?

    • Hey Jakub,

      first of all: sorry for my late answer. Usually, I’m faster.

      To respond to your question: No, I didn’t implement any improvement. Actually, the PR shows how not to do it. In the example above, the code strongly depends on a detail – the particular event bus. Even both event bus implementations (Guava and Spring) are doing very much the same, I cannot switch from one to another without touching a huge part of my code. The code depends on the detail of which event bus is beeing used, because there’s not abstraction. So a minor change (switching from Guava to Spring) requires me to edit 18 files.

      To improve this situation, I would recommend to implement a custom event listener annotation. This annotation can hide the actual implementation whether it’s Spring, Guava or even some middleware like Kafka.

      To your question about XML: I love using annotations and I don’t miss the XML configurations from back in the days. I like the fact to have everything in one place – my code.

      Best regards.