Article 3X99E Representative Line: You Can Only Get What You Have

Representative Line: You Can Only Get What You Have

by
Remy Porter
from The Daily WTF on (#3X99E)

Sean's ongoing career as a consultant keeps supplying him with amazing code.

Let's talk about encapsulation. We put getters and setters around our objects internalsto help keep our code modular. Given an object, we call something like getUsername to extract a piece of that object safely.

In the same codebase as IsTableEmpty, Sean found this short-but-sweet gem:

public String getUsername(String username){ return username;}

This version of getUsername requires you to already have the username. Oddly, it behaves unpredictably, as if you pass it a postal code, it returns the postal code, and doesn't complain that it isn't a username.

proget-icon.png [Advertisement] Ensure your software is built only once and then deployed consistently across environments, by packaging your applications and components. Learn how today! TheDailyWtf?d=yIl2AUoC8zAKqhRcZOa5HY
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments