Object-Oriented Approach for Model Factory #4437
HasanAshab
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Hello @HasanAshab Thanks for the proposal. I will consider it once we will do any major changes to Lucid and that will take some time. |
Beta Was this translation helpful? Give feedback.
1 reply
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
Here is a small example of the idea:
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