well if you wanted to get into the nitty gritty about object-oriented design then the code you posted above is generally looked at as 'bad'. As it violates the 'Law of Demeter':
More formally, the Law of Demeter for functions requires that any method M of an object O may only invoke the methods of the following kinds of objects:
1. itself
2. its parameters
3. any objects it creates/instantiates
4. its direct component objects
In particular, an object should avoid invoking methods of a member object returned by another method.
http://en.wikipedia.org/wiki/Law_of_Demeter
Generally, when you start going down the chain of objects to get to a certain field then sometimes there might either be some un-needed complexity or bad design.
accessing your object like:
player.getLastPosition().getTransform().getX()
can generally lead to debugging headaches because now your player class knows intimate details of those lower level classes, so should something change (ie method names/signatures) you start getting errors in your code.
having a player.getX() method that delegates it further down into your classes is usually a safer way, but going too far with that methodology I think causes some other issues.
More formally, the Law of Demeter for functions requires that any method M of an object O may only invoke the methods of the following kinds of objects:
1. itself
2. its parameters
3. any objects it creates/instantiates
4. its direct component objects
In particular, an object should avoid invoking methods of a member object returned by another method.
http://en.wikipedia.org/wiki/Law_of_Demeter
Generally, when you start going down the chain of objects to get to a certain field then sometimes there might either be some un-needed complexity or bad design.
accessing your object like:
player.getLastPosition().getTransform().getX()
can generally lead to debugging headaches because now your player class knows intimate details of those lower level classes, so should something change (ie method names/signatures) you start getting errors in your code.
having a player.getX() method that delegates it further down into your classes is usually a safer way, but going too far with that methodology I think causes some other issues.