Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

42
  • 3
    @Ewan The word getter here is not used to mean a getter technically but any kind of method (getters included) that returns the internal state of an object. Commented May 11, 2024 at 21:06
  • 4
    @Ewan Getters are methods for returning state, there being special syntax in some languages for nicer usage is immaterial. Commented May 11, 2024 at 21:06
  • 41
    "A getter is a failure to design an object." - I think that the crux of the issue is that this is too general a statement, taken at face value. What many people do with getters is they just expose each private field. While this offers some level of indirection, it is minimal, and if your goal was to encapsulate the internals in the first place, then doing this soon makes it difficult to change those internals, or to extract a sufficiently abstract interface, without a bunch of rewriting. That's what people caution against. But if getting out a value is a core behavior, a getter is fine. Commented May 11, 2024 at 23:06
  • 14
    It is quite clear you want to give Robert B. a stage with this question. But maybe a more honest title would have been "How far can you push Robert B's idea of Object Oriented Programming", or "How far can you push Tell-Don't-Ask". because that is IMHO the core point of Robert's approach to OO. Note also that there are other schools-of-thought, people who don't conflate OOP with TDA. Commented May 12, 2024 at 6:17
  • 10
    You -- or someone you are referring to, I can't really sort it out here -- may be suffering from what I call Object Happiness Disorder: the belief that OOP is a goal in itself, rather than one technique for achieving a goal. The question to ask is not "is this choice aligned with OOP dogma?" but rather does this choice make my program more correct, legible, usable, robust, feature complete, extensible, or whatever actual goals you have. Commented May 13, 2024 at 17:50