Couple months later

After some time our middleware has many more use cases to handle. Therefore a lot of new functions like this came up and a lot of these test cases came up as well.

We find out that we have to change our HTTP server (express) because it is too slow and some new fancy HTTP server has just come up.

So we go into the code and realize…. that… well… we are pretty much doomed.

WHY??

Because we have to change EVERYTHING.

Yes, I mean everything. Just look at our code, we have express everywhere. In our tests and in our production code.

We tightly coupled our high-level policy with low-level details like express response and request object.

Just look at the code. If we want to change our HTTP server we have to go through the whole code base and change the API of the express request and response object to the API of the new server.

Our old test snippet.

Old Express API

New snippet with changed API.

New Fancy Server API

Old production code.

Express API

New one.

New Fancy Server API

Couple months later #2

We somehow managed to change our HTTP server to the new one (after a lot of time spent).

Couple months later #3

Our product owner came to us that we have to change our external HTTP endpoint to another one which has completely different API.

So we run our IDE and realized…

well…

We are pretty much fuc***, doomed. That we are pretty much doomed again.

And WHY??

because again, we coupled our low-level detail (the external API) with our high-level policy everywhere.

Just look at the code, we have to go through our code base again and change the API of our external HTTP endpoint.

This is how the old external endpoint looks.

Old Endpoint

The new API.

New Endpoint

The class diagram of whole Login use case looks like this.

So… how do we fix that?