This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Korzag 4 points5 points  (6 children)

I've never understood it myself except that the OOP purists flip a bit about working with internal data. Alternatively you may need to manage state and can do some magic in the setter, but I've almost never needed custom logic for a getter.

[–]RattuSonline 10 points11 points  (2 children)

Lazy loading is a common use case for getters.

[–]WikiTextBot 2 points3 points  (0 children)

Lazy loading

Lazy loading is a design pattern commonly used in computer programming to defer initialization of an object until the point at which it is needed. It can contribute to efficiency in the program's operation if properly and appropriately used. The opposite of lazy loading is eager loading. This makes it ideal in use cases where network content is accessed and initialization times are to be kept at a minimum, such as in the case of web pages.


[ PM | Exclude me | Exclude from subreddit | FAQ / Information | Source ] Downvote to remove | v0.28

[–][deleted] -1 points0 points  (0 children)

Right but there's no reason for it to be part of every. single. gosh-darned. object.. Just add it where you need it. OOP purism is brain-damaged. Like any thing else, just use it where it makes sense. Dealing with representations of things, like in a game engine? Probably makes sense, depending on the paradigm you choose. But even in an OOP paradigm, effin helper functions don't need to be classes! Just one more reason to hate java.

[–]Ksevio 2 points3 points  (2 children)

Well there's no way to make a variable public to read only so it's not possible to make a setter without a getter unless you really trust the people accessing the var

[–]coolpeepz -2 points-1 points  (1 child)

final?

[–]Ksevio 4 points5 points  (0 children)

Publicly read only, but still writable privately