
reference.language.category_methods_getters.html Maven / Gradle / Ivy
Categories
Getters
Category attributes can be accessed using instance.name
, where instance
is a value and name
is the name of a an attribute supported by this value.
This covers most use cases, but there are situations where you want the returned value to be computed, rather than just read from the object.
This is where getters are useful.
Getters are special methods defined as part of a category definition, and attached to a particular attribute name.
When a getter is defined and a piece of code tries to read the corresponding attribute, Prompto will call the getter instead.
In the below example, we define a getter for a fullName attribute:
Cyclical dependencies
Prompto manages cyclical dependencies between getters. Cyclical dependencies occur when for example getter for 'a' reads 'b' and getter for 'b' reads 'a'.
During the execution of a getter body, it is guaranteed that the getter being executed will not be called again for the current object
until the execution of the initial getter is complete.