You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Static functions can be dynamically **mocked per instance** without modifying the component.
68
+
- There is **no need** to create instance wrapper functions for static functions.
69
+
- Static functions can be dynamically **mocked per instance** without modifying the class.
69
70
- This allows for **cleaner test code** and avoids unnecessary duplication.
70
71
72
+
## Retrieving Static and Instance Function Metadata
73
+
74
+
Lucee provides a way to retrieve metadata for both static and instance functions using `getMetadata`. The structure of the returned metadata is identical for both, with the only difference being a `static` flag:
This means that **static and instance functions are represented the same way in metadata**, with the `static` flag indicating whether a function is static or not.
91
+
71
92
## The Benefit of Static Functions
72
93
73
94
1.**No Difference in Access** – Static functions work exactly like instance functions.
74
95
2.**Ease of Mocking** – Static functions can be mocked at the instance level, avoiding unnecessary wrappers.
75
96
3.**Consistency** – Static functions ensure a uniform implementation across instances while still allowing for instance-level customization when needed.
76
-
4.**Overlay vs. Overwrite** – When an instance function is redefined (mocked), it overwrites the original implementation for that instance. With static methods, defining an instance-level function of the same name overlays the static method for that instance only, while the original static method remains accessible via the class.
97
+
4.**Overlay vs. Overwrite** – When an instance function is redefined (mocked), it **overwrites** the original implementation for that instance. With static functions, defining an instance-level function of the same name **overlays** the static function for that instance only, while the original static function remains accessible via the class.
77
98
78
99
## Conclusion
79
100
80
-
Lucee’s handling of static functions provides a powerful way to structure shared functionality while maintaining flexibility in testing. Instead of introducing redundant instance function wrappers, developers can take advantage of the fact that static functions are accessible like instance functions and can be dynamically mocked per instance. This results in a cleaner, more maintainable codebase.
101
+
Lucee’s handling of static functions provides a powerful way to structure shared functionality while maintaining flexibility in testing. Instead of introducing redundant instance function wrappers, developers can take advantage of the fact that static functions are accessible like instance functions and can be dynamically mocked per instance. Additionally, `getMetadata` provides an easy way to differentiate between static and instance functions, reinforcing the consistent handling of both in Lucee.
0 commit comments