Skip to main content

Posts

Showing posts from February, 2020
              Don’t use Setters and Minimize Getters In the modern IDE’s, getters and setters are created automatically or in some cases including a specific library creates them automagically, injecting these accessor methods. This so-called feature of the IDE is cool but evil! We also have libraries that do this in code, like Lombok. Programmers don’t write these methods and the IDE enables us to do these incorrect things quickly. Let me take a step back for a moment. I know a lot of you are surprised by the topic name and let us get into the details of it. In an object-oriented world, an object represents a real-world entity. You always interact with the object through its behavioural methods. What these getters/setters do is that they expose the internals of the object and provide you with a mechanism to modify an object's internal state. Let us take an example. Suppose you have an employee object with the following data Employee Object