What are the benefits of the following codes?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JulioYagami

I was studying Godot best practices and I found these code blocks:

# First example:
# Parent
$Child.func_property = funcref(object_with_method, "method_on_the_object")

# Child
func_property.call_func() # Call parent-defined method (can come from anywhere).

# Second example:

# Parent
$Left.target = $Right.get_node("Receiver")

# Left
var target: Node
func execute():
    # Do something with 'target'.

# Right
func _init():
    var receiver = Receiver.new()
    add_child(receiver)

So I wanted to know what are the benefits ot these practices?

I don’t know much about this code. But the first portion (with the parent and child) seems to be a form of dependency injection.

Ertain | 2019-09-29 03:21