Designing with Ports and Adapters
In this lesson, you will learn about the Ports and Adapters design pattern and how to implement it in applications.
We'll cover the following...
Next, you’ll need to modify the ShowFormFunction
Lambda function to validate the requested extension and return an error message in case of unsupported extensions. The function you wrote in the previous chapter was still relatively easy to read and understand. Putting more logic into that function definitely pushes it beyond the threshold of what could be considered simple.
A big part of making robust code is the ability to understand it easily and modify it with confidence. Both those goals are more attainable with some nice unit tests. However, your current function design is not really making that easy. The function directly talks to S3, requiring IAM privileges to execute, and it depends on several environment variables that need to be configured upfront. Automated tests for this function would be slow and error-prone and it would be difficult to set up all the testing dependencies. This would be a good time to redesign the code and prepare it for future evolution.
Ports and adapter design pattern #
At MindMup, we use the Ports and Adapters design pattern (also called hexagonal architecture ...