Currently I am developing a webapp where I have defined models implementing the Active Record pattern. Each model also is defined by an interface that specifies the Entity properties and makes it easy to inject it into other classes, specially useful for unit testing. I am looking forward to implement each model with a Repository pattern to abstract the database implementation.
ArticleInterface - title - content ArticleRepositoryInterface - getArticle(title) - saveArticle(ArticleInterface) ArticleRepository implements ArticleRepositoryInterface - constructor(ArticleInterface) - ArticleInterface getArticle(title) - saveArticle(ArticleInterface) Article implements ArticleInterface extends ActiveRecordModel
Both patterns are very popular in today web development frameworks, but It is not clear to me how to integrate them. The Active Record pattern by definition wraps a row in a database table, encapsulates the database access, mapping each object property to a database table, so
how should you integrate each model repository with the model that implements the AR ?
Are there any alternatives to using a model that implements the AR, inheriting all the database methods, and injecting it into a Repository wrapping all the AR database methods?
What are the best practices in this scenario?