12

The Law of Demeter (“talk only to your friends”) is a good place to start, but think about it this way: you can play with your toys, with toys that you make, and with toys that someone gives you. You don't ever, ever play with your toy’s toys.

Source: The Thoughtworks Anthology

What could the last sentence mean? Could a toy have a toy? Assuming a toy means "A toy is an item that is used in play", a toy can never have a toy, so one cannot play with a toy’s toys (it's physically not possible).

The context is object oriented programming.

9
  • 3
    This seems more appropriate for Philosophy.SE as it is not a question about the English language (the question could be equally posed in any language).
    – Mitch
    Jun 19, 2019 at 12:19
  • 2
    Presumably that's why the quoted passage says you never do it! Jun 19, 2019 at 14:19
  • 25
    I don't know that the non-programmers here will understand the context neccessary.
    – tchrist
    Jun 19, 2019 at 18:09
  • 9
    I'm voting to close this question as off-topic because it belongs on another site in the Stack Exchange network, the context being OOP. Jun 19, 2019 at 21:49
  • 3
    @Mitch lol! No, it belongs on Software Engineering.
    – jpmc26
    Jun 20, 2019 at 21:27

4 Answers 4

42

Toys absolutely can have toys. For example, this “Barbie Kelly Playroom” comes with stuffed animals, dolls, a play kitchen, and UNO for Kelly (Barbie’s sister and a toy):

Barbie playhouse

In this case, it would be possible to play with Kelly’s toys directly (with the exception of UNO, which is almost certainly just a box). However, what you’re supposed to do is have Kelly play with her toys.

12
  • 4
    Definitely still a strange wording, since I would consider that playing with my toys and having them play with toys as I play with them is still really me playing with the toy's toys. It's just a really strange analogy because toys have no agency of their own to play with toys, so any instance of a toy playing with their toys is really you playing with the toy's toys.
    – JMac
    Jun 20, 2019 at 12:31
  • 3
    @JMac: It's thinking at two levels of abstraction at once, a necessary skill for programmers. I can see how it's hard to get.
    – Joshua
    Jun 20, 2019 at 18:05
  • 2
    @JMac In this analogy, the play you are engaged in is imagining that your toys are real people with the agency and ability to play with their own toys. (Even if you're the one physically moving them about, they still only move because your toys "wanted" them to.) Without adding that layer of imagination, all the "toy's toys" are a bunch of tiny, low quality pieces of badly molded plastic that you probably wouldn't bother to play with at all.
    – jmbpiano
    Jun 20, 2019 at 18:17
  • 7
    @JMac It's not a great analogy, but it's not horrible either since as an OOP programmer, you're often the one responsible for both the implementation of the "toy" and also the "toy's toy", but you have to mentally restrict yourself from relying on the details of the implementation of one when you create the other, lest you make a rats nest of unnecessary interdependence. You shouldn't care about playing with your toy's toy, no matter how much your toy "likes" playing with it.
    – jmbpiano
    Jun 20, 2019 at 18:17
  • 1
    @JMac What analogy would you use if you had toys, each with their own set of assigned toys, but you had to discipline yourself to not play with your toy's toys directly? In OOP, the distinction between toy and toy's toy is completely arbitrary. But if you don't discipline yourself with how you play with them, you will end up with a tangled mess. While the analogy is hard to understand, to be honest I don't know how better way to express it.
    – Tezra
    Jun 20, 2019 at 21:06
56

This question seems to be about programming rather than English language, and would probably be better on Stack Overflow… That said, I'll answer it anyway:


Without a context, this doesn't make much sense. But working backwards from the fact that the context is object-oriented programming, and thus kind of 'reverse-engineering' the question, if you will:

It's saying that in OOP, in your implementation of a class, you can access and modify properties of instances of the class you are implementing itself ("your toys, toys you make") and data that's passed into instances of that class such as when it is instantiated ("toys you're given"). But you shouldn't modify private properties of other objects directly, even if you own those objects ("your toys' toys") because that can result in unexpected or undefined behaviour.

It's a pretty bad analogy.

5
  • 17
    "pretty bad analogy".. Ah, that explains things. I'm a programmer and I couldn't make heads or tails of it.
    – Mr Lister
    Jun 20, 2019 at 6:45
  • 3
    Maybe a better analogy is food rather than toys. Jun 20, 2019 at 8:59
  • 2
    This is the appropriate meaning
    – Stilez
    Jun 20, 2019 at 11:21
  • 1
    @OldBrixtonian I don't see how "boys' toys" would work in the quotation in the question; how would you then interpret the sentence?
    – Caesar
    Jun 21, 2019 at 8:04
  • I am not a programmer, so is OOP a computer language? EDIT It's object oriented programming. I think you have posted the right answer because I cannot make head nor tail of it :)
    – Mari-Lou A
    Jun 25, 2019 at 4:44
1

Laurel's answer explains the the meaning of the pure english part of the analogy, but for completeness I just want to add what this analogy means in OOP terms.

If you think of Objects (class instances) as toys, and you yourself are also a toy (the logic of a class object); you can play with your toys (globals/properties of that class), with toys that you make (new/declared variables), and with toys that someone gives you (parameters). You don't ever, ever play with your toy’s toys (the internal globals/properties of the previously listed Objects you can play with).

And like the doll set in Laurel's answer, as the programmer technically all of the "toys" are really "your toys". In OOP, it is perfectly valid to play with your toy's toys. If you do however, you wouldn't be using the toys in the way they were intended to be used.

2
  • Apart from affording English less respect than oop, this would seem to be a perfect answer, but shows that it is primarily an OOP question. Jun 22, 2019 at 13:59
  • Upvoted because I understood the explanation. It also explains why the question generated so many views.
    – Mari-Lou A
    Jun 25, 2019 at 4:46
0

As other people have said, it's a badly worded analogy, around the fact that you shouldn't directly interact with items you don't directly own (or have been given permission to interact with).

A better analogy would be: you have a sandwich, and your partner has a sandwich. You can eat your sandwich if you want, but you shouldn't eat your partner's sandwich without their permission. Otherwise, there may be trouble when they get and try to eat it...

Not the answer you're looking for? Browse other questions tagged or ask your own question.