Why your interface cannot consist of a single class

Reading time:

1–2 minutes

Dear reader, it’s almost 2025 and in my experience we are connecting more IT systems via interfaces than ever before. Recently I have seen several REST-based interfaces implemented in ABAP to use data from third-party systems in SAP ERP systems.

I have noticed a few negative things about these interfaces that I would like to address in this blog. In addition, I would also like to give some food for thought on how things can be done differently.

What was striking

For some reason, they all had the following characteristics:

  1. Complete interface in one class
  2. Class had hundreds, sometimes thousands of lines of code
  3. No unit tests
  4. No or poor exception handling

In this blog I would like to address points 1) and 2) in particular. The other points could be the subject of further blogs.

In my view, it’s striking that one class does the work alone. In this context, this is a sure sign that the Single-responsibility principle (SRP) has not been taken into account. As a result, you have problems with the testability and overall maintainability of the interface.

What could be done better

Because an interface should consist of an interaction of different objects (like pretty much everything in an object-oriented world), here’s a simple class list as a starting point for your own work.

Your REST-based interface should have one or more classes to represent the…

  1. Uniform Resource Identifier (HTTPS access point of the interface, possibly as a value object)
  2. Connection
  3. Interface itself
  4. Request
  5. Response
  6. Converter (to read the business data from the response)
  7. Business data (payload)
  8. Protocol
  9. Exceptions (one general interface exception class or better different specialized exception classes)

Summary

The presented list of classes for implementing an interface is a good starting point for your own design.

By having different classes for different tasks (SRP) and loosely coupling those classes, the foundation for testability and maintainability is laid.

Have fun trying it out

Michael