Use class-based services instead of functions #1381
Unanswered
NickSeagull
asked this question in
Refactors and standards
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently all "services" in the codebase are just modules with exported functions.
Using a class-based approach with a separation of interface and implementation for services is better than using regular exported functions because it provides clear separation of concerns, encapsulation of related data and functions, and more maintainable code.
Not also this leads to better to code organization, but also in terms of testing, we are essentially doing hacks to replace the functions of the services in runtime, where by adopting a class based approach would allow us to create the instances directly, which would make our testing process more efficient and effective. This would simplify our testing process and reduce the risk of errors caused by these runtime replacements.
A class-based approach with interface and implementation separation enables the usage of dependency injection by defining interfaces for services and injecting different implementations of these interfaces into classes, resulting in more flexible and adaptable code.
Related discussions
Beta Was this translation helpful? Give feedback.
All reactions