Answer the question
In order to leave comments, you need to log in
Repository pattern and Active Record?
Hello! There was such a question, please explain, the Repository pattern contains only the logic of working with the object, selection, etc., but without saving it to the database, but if the Repository contains methods that save, delete the object, does the Repository turn into an Active Record? correct me if I'm wrong somewhere
Answer the question
In order to leave comments, you need to log in
What is a repository? This is something that is responsible for storing data. Completely. That is, here is a simple interface of a simple repository:
interface UserRepository {
public User getUser(UserID id);
public void add(User user);
public void remove(User user);
}
A repository is a repository for all objects of a certain class at once. Repository methods that add or remove an object take that object as a parameter. The repository methods responsible for searching return instances of the found objects. You have one repository instance for all the objects it can store (usually one instance for all objects of a single class or class hierarchy).
In the Active Record pattern, an object can save itself. In other words, the responsibility for storage issues lies with the facility itself.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question