Hello everyone!
I have a background as a Java Backend Developer so I already know there is nothing too wrong or too right on this case, since it is a very simple scenario.
What I’m looking for are thoughts and opinions about the overall design of my grabber: is it better than others? Is it for the good reason?
So this definitely wants to be a “high level” discussion about a mostly theoric and picky question, and I am already aware how little they are relevant in a pragmatic world as it is professional programming.
Anyway, the lecturer uses the methods
FVector GetPlayersWordPos()
FVector GetPlayersReach()
Which is an approach I like, also very similar to how you do in Java, so familiar to me.
What I did instead is to always refer to private members and use void methods to update them.
Grabber.h
private:
FVector LineEnd {0.f,0.f,0.f};
FVector PlayerViewPointLocation {0.f,0.f,0.f};
FRotator PlayerViewPointRotation {0.f,0.f,0.f};
Grabber.cpp
void UGrabber::UpdateReach()
{
GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(
OUT PlayerViewPointLocation,
OUT PlayerViewPointRotation
);
LineEnd = PlayerViewPointLocation + (PlayerViewPointRotation.Vector() * PlayerReachInCentimeters);
}
The reason why I did this is because I considered that, in this specific scenario:
- Position and Reach (which I called LineEnd) are always updated together so their update can be (quotes) “an atomic operation” (I even considered to replace them with a struct)
- Position and Reach (at the current state of the project) will never be used by anyone but Grabber.cpp, so they should be as hidden as possible to the outside
- Position and Reach are updated continuously so I thought it was more logical (and performant, but by an irrelevant amount) that they should always be seen as members rather that something accessed by a function, for which I prefer it does some more logic.
The approach of the Getters however is good because:
- Makes the code slighly better to be read
- It is more changes-proof
What are your thoughts about it?