Skip to main content
17 events
when toggle format what by license comment
Jan 22, 2021 at 23:13 comment added user3153970 @FilipMilovanović good point, mind wrapping/extending as an answer?
Jan 22, 2021 at 13:43 comment added Filip Milovanović LoD basically tries to guide you away from writing procedural code. Consider why you want the personInfo object, and why you want to return it from isRegistered, and can you make attendance do that work instead. Perhaps you'd have to preconfigure the attendance object somehow in order to achieve that. Perhaps you'd have to reconceptualize and redesign things that interact with that class. That said, even in an OO system, there can be procedural bits. Sometimes an object can just be a data bag. 2/2
Jan 22, 2021 at 13:42 comment added Filip Milovanović The essence of Law of Demeter is that it's a set of guidelines aiming to help you (1) limit the number of interconnections between classes, and (2) prevent you from treating objects as data bags from which you take out some data and manipulate it. It's closely related to the "Tell, Don't Ask Principle". The rules (which are, again guidelines) should be subservient to those ideas - it's pointless to blindly follow them if you're not working towards that goal. 1/2
Jan 22, 2021 at 5:01 history protected gnat
Jan 22, 2021 at 1:42 answer added candied_orange timeline score: 2
Jan 21, 2021 at 15:16 answer added Laiv timeline score: 3
Jan 21, 2021 at 14:34 comment added Laiv Curiously, if we consider the premises introduced here, the OP example doesn't break LoD, until it does something like personInfo.doSomething(). If Attendance and Conference are "unrelated" units as for this to break LoD, we don't know.
Jan 21, 2021 at 14:11 comment added Laiv @RobertBräutigam Everything in excess is counterproductive. Too much chocolate can kill you. That said, I don't think getters defeat LoD per se in every single use case. It depends on the context and the visibility of the getter. We can argue that getters often (if not always) defeat encapsulation, but as in many other principles, encapsulation happens at different levels of abstraction-
Jan 21, 2021 at 11:22 comment added Robert Bräutigam @Laiv I think it is a three-strike system. You might not go to hell for the first getter, but I think you definitely should by the third or so. :) Seriously though getters are the most clear and reliable sign of a defective design. The more there are, the worse the design usually is.
Jan 21, 2021 at 10:27 answer added Robert Bräutigam timeline score: 3
Jan 21, 2021 at 10:21 comment added Flater @gnasher729: "I should wrap this just to be safe" is a thought process that's prone to infinite recursion. I've seen countless examples of developers who take their "one more abstraction" approach to insane levels and end up abstracting for abstraction's sake. Questioning whether an additional abstraction is warranted and meaningfully contributes is not madness, so it should leave your mind rather unboggled.
Jan 21, 2021 at 9:58 comment added Laiv @gnasher729 because getters have been so reviled that new developers look at them as forbidden or bad practice. So if I don't write getter, I won't go hell at the of this so confusing existence.
Jan 21, 2021 at 8:35 answer added JayZ timeline score: 0
Jan 21, 2021 at 8:11 comment added gnasher729 It boggles the mind why you would think that accessing the data directly would be better than getting it using an accessor.
Jan 21, 2021 at 4:42 review Close votes
Jan 26, 2021 at 3:02
Jan 21, 2021 at 2:28 history edited lennon310 CC BY-SA 4.0
added 19 characters in body
Jan 21, 2021 at 2:22 history asked user3153970 CC BY-SA 4.0