Junior — Middle
Have you had experience working with design patterns in your projects?
sobes.tech AI
Answer from AI
Yes, in my projects I have used various design patterns such as Singleton for managing access to a single instance of a class, Repository for abstracting data access, and Factory for creating objects without tight coupling to specific classes. For example, the Repository pattern helps separate database logic from business logic, which improves testability and maintainability of the code.
public interface IRepository<T> {
void Add(T item);
T Get(int id);
}
public class UserRepository : IRepository<User> {
public void Add(User user) {
// add user to database
}
public User Get(int id) {
// get user by id
}
}