title: Clean code: preventing unexpected behavior when caching mutable instances
body: <p>Suppose I have the following 2 classes:</p>
  <pre><code>extends Resource
  class_name MenuItem
  
  export var food: Texture = preload(&quot;Burger.png&quot;)
  export var drink: Texture = preload(&quot;Soda.png&quot;)
  
  </code></pre>
  <pre><code>extends Node
  class_name Meal
  
  # &quot;Public&quot; variable
  var menu_item: MenuItem setget _set_menu_item
  
  # &quot;Private&quot; variables
  onready var _food: Sprite = $Food
  onready var _drink: Sprite = $Drink
  
  
  func _set_menu_item(value: MenuItem) -&gt; void:
      menu_item = value
      _food.texture = menu_item.food
      _drink.texture = menu_item.drink
      
  </code></pre>
  <p>The problem is that I bypass the mutator if I cache the <code>menu_item</code> property:</p>
  <pre><code>extends Node
  
  onready var meal: Meal = $Meal
  onready var menu_item: MenuItem = meal.menu_item
  
  
  func _ready() -&gt; void:
      # Will trigger `_set_menu_item` and update `_food.texture`
      meal.menu_item.food = load(&quot;Salad.png&quot;)
      
      # Won't trigger `_set_menu_item` and won't update `_food.texture`
      menu_item.food = load(&quot;Soup.png&quot;)
  
  </code></pre>
  <p><strong>While keeping both classes mutable,</strong> how would you ensure that <code>Meal</code> always behaves as expected and updates its sprites when <code>menu_item</code> is changed?</p>