They discuss a 'red square' object (added to a JPanel) painting itself by accepting a graphics object, making the code cleaner - and I get that.
I just find myself wondering why I don't also have the red square class deal with the 'move' logic too? Personally I would've thought that the square would deal with its own movement, but can see the reasoning for a panel to move an object around. Is it just a design decision, or is there a good reason for this particular set up that i haven't quite spotted? Apologies if this is a silly question, pretty new to all this swing stuff
I think you actually have a point in calling out that design because the code looks like it violates the Tell, Don't Ask Principle of object-oriented design. It's really more interested in getting values from the red square and making calculations. Flipping that around would push the calculations back into the square, which keeps the information and the calculations closer together within the same class. That's what encapsulation is about. The current design is arguably less well-encapsulated.
like i said i'm no expert, so I'll pretend that's what I meant..... but eitherway it didn't quite seem right - sort of like a bad attempt to loosen the coupling between the two - which it isn't doing well anyway.