The Eric Normand Podcast

Why getters and setters are terrible

Jul 4, 2019
Explore the pitfalls of using getters and setters in programming, as they often turn classes into mere data holders lacking essential functionality. The discussion emphasizes the need for better API design and encapsulation to enhance class structures. It also critiques the traditional approach within object-oriented programming, tracing its roots to the Java Bean specification and advocating for more impactful programming practices.
Ask episode
AI Snips
Chapters
Transcript
Episode notes
INSIGHT

Getters and Setters Create Bespoke APIs

  • Getters and setters turn classes into glorified data structures with bespoke APIs.
  • This creates reuse issues and forces consumers to learn unique method sets.
INSIGHT

Data Modeling and Getters/Setters

  • Getters and setters delay dealing with data changes, leaving it to other code to manage.
  • This neglects the meaning and context of data manipulation within the class.
ANECDOTE

Employee Salary Example

  • An employee's salary changes can have various meanings (e.g., correction, raise, pay cut).
  • Setters without context fail to capture these nuances, treating the class as mere storage.
Get the Snipd Podcast app to discover more snips from this episode
Get the app