Open LeTraceurSnork opened 4 weeks ago
@szepeviktor @felixarntz if you want, I can submit a short fast PR with an example of that type of hierarchy just to clarify what kind of interfaces I'm talking about
@LeTraceurSnork Thanks for raising this!
I like the idea of dedicated getters and setters. That said, it would be great to maintain the ability of passing the WP typical "array of args". I think we could achieve both, so that the API could be used in either way.
One note about the code example: For this library, we should continue to follow the WordPress coding standards, i.e. snake_case instead of camelCase.
I suggest consideration changing the architecture of the
Felix_Arntz\WP_OOP_Plugin_Lib\Entities
namespace so that models would have named fields with their own getters and (optionally) setters. For example, $post->getId(); $post->getTitle(); $post->getContent();. The repositories working with these models would then accept the models themselves as arguments, rather thanarray $data
. This would allow to populate the models with data first (or even provide factories) and then save them directly through repositories without worrying about field names, required fields, or the quantity of fields needed. In other words, simply create a model, pump it with data, pass it to the repository, repository saved it — done!An example using interfaces: