Clean Code: Method Arguments Must Be Crisp and Encapsulated

While writing methods, please pay close attention to the method arguments. This is the one area where the method assimilates the foreign body into its core body. Foreign material is always dangerous, you do not have any control over it, but as an owner of a method, you can put a defensive mechanism aka validation, or the anti-corruption layer of your method.

Tip 1

Always put validation on the input argument, you can use java annotations to do the validation.

Clean Code Tips 1: Use Top-Down Approach While Converting Complex Logic Into Methods

To know how to write clean Method is the stepping stone of writing proper clean code. You already know common things like method should be clean, readable, giving proper names, so I will not write on this. I will focus on the flow of the method, and there are two ways to write a complex logic:

  1. Top-down approach
  2. Bottom-Up approach

For clean code, always choose the top-down approach. There are several advantages.