- Edited
I just learned about Law of Demeter and as I see it contradicts all the Godot youtube tutorials. The law says
An object can call methods that are apart of
- the same object.
- a parameter passed into the method.
- a object created within its method.
- an object it owns.
- a global variable.
This implies that any action this object takes must be by manipulating objects of no more than 1 degree away from it. A parent can tell their children what to do, but are not allowed to tell their grandchildren what to do. A manager should manage their direct subordinates, but definitely not manage their subordinates subordinates.
But in Godot something like this is considered normal (C#):
public void SetPriceText(float value)
{
GetNode<Label>("Viewport/VBoxContainer/Price").Text = value.ToString("#.#");
GetNode<Viewport>("Viewport").Size = GetNode<VBoxContainer>("Viewport/VBoxContainer").RectSize;
}
This method is in scene's root node script. It calles not only its child "Viewport" but event grand and grandgrandchildren. So to satisfy the law I should add script for each node of path "Viewport/VBoxContainer/Price" and create a method for each script that returns child or itself or size or whatever. It seems like a tedious and unnecessary work. Is this law not suitable for Godot? Maybe this law not applicable for engine-based game development at all?