Chain of responsibility
I'm a horrible software architect, and I don't like to speak with people. Hence, while sitting in The Ivory Tower (that's the name of the cafe I often visit), I wrote a small web application. If a developer has a question, he shouldn't approach me directly, oh no. He'll need to send me a proper request through this system, and I shall answer him only if I deem this request worthy.
A filter chain is a very common concept in web servers. Usually, when a request reaches to you, it's expected that:
- Its parameters are already validated
- The user is already authenticated, if possible
- User roles and permissions are known, and the user is authorized to perform an action
So, the code I initially wrote looked something like this:
fun handleRequest(r: Request) { // Validate if (r.email.isEmpty() || r.question.isEmpty()) { return } // Authenticate // Make sure that you know whos is this user if (r.email.isKnownEmail()) { return } // Authorize // Requests from juniors are automatically...