Getters and Setters are bad OO design?

Julio picture Julio · Apr 30, 2010 · Viewed 12.7k times · Source

Getters and Setters are bad

Briefly reading over the above article I find that getters and setters are bad OO design and should be avoided as they go against Encapsulation and Data Hiding. As this is the case how can it be avoided when creating objects and how can one model objects to take this into account.

In cases where a getter or setter is required what other alternatives can be used?

Thanks.

Answer

Cory Petosky picture Cory Petosky · Apr 30, 2010

You have missed the point. The valid, important bit of that article is:

Don't ask for the information you need to do the work; ask the object that has the information to do the work for you.

Java-style getter and setter proliferation are symptoms of ignoring this advice.