In unity's GameObject class, there are a few default data members. When we add a component to the game object, light for example, where exactly does it get added? Does it become a part of the GameObject class?
In the past, components used to be added to the GameObject itself, in such a way, that you could call
myGameObject.renderer to get an object's
This however changed to the call of
myGameObject.GetComponent<Renderer>(), which hides the details of where the components are saved, which shouldn't be relevant anyway. Since for most (if not all) cases it doesn't matter for the user where components are, but that they belong to an object.
As @DMGregory noted, when you (used to) refer to a component with the first way (
myGameObject.renderer) it acts like a getter behind the scenes, so the
GetComponent function just replaced that, it still seems to work the same way, as in, you can get a component from a
GameObject but the implementation details are unclear and not needed.