Object-Oriented Approach for Lucid Model Factories #4340
Closed
HasanAshab
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Dear AdonisJS Team,
I hope this message finds you well. I've been using AdonisJS for quite some time, and I appreciate the elegance and power it brings to web development. Today, I'd like to propose an enhancement to the existing Lucid model factories by adopting an object-oriented approach.
Currently, Lucid model factories are functional, and while they serve their purpose, I believe embracing an OOP paradigm could lead to cleaner, more maintainable, and extensible code. To demonstrate this, I've created a base factory class that introduces features like state customizers, external callbacks, and configuration options:
To illustrate the new factory design, I've extended it with the
UserFactory
:Now the User model can extend HasFactory Trait
Useage
By adopting this OOP approach, we can easily extend and customize factories for specific models. I believe this change would enhance the readability, maintainability, and extensibility of the existing factory system.
Thank you for considering this proposal. I'm open to discussions and feedback.
Best regards,
Hasan Ashab
Beta Was this translation helpful? Give feedback.
All reactions