KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've been becoming more familiar with the Factory Pattern (along with Strategy Pattern) and what a great benefit the pattern can have. However, I've been struggling with the following situation: Previously, I would have done something like the following, where there's a manager class that would build and save a Car. There's no dependency injection here and is a poor implementation, especially when trying to unit test. public class CarManager { public static Car GetCarFromDatabase(int carId) { return new Car(); } public static void SaveCar(Car car) { } } I see now how I could have different Factories that build cars for me, whether it be from a database, or wherever! This is great! So, here's my questions: Q1: It's my understanding that Factories should only build objects, is that correct? If so, what about my second question? Q2: If I'm following the Factory Pattern for building my objects, how should I go about saving my objects? Is there a different pattern for this, or am I not completely understanding the Factory Pattern?
Tags (comma-separated)
Save Edits
Cancel