<p>This might be on the "discussy" side, but I would really like to hear your view on this.</p>

<p>Previously I have often written data access classes that handled both reading and writing, which often led to poor naming, like FooIoHandler etc. The rule of thumb that classes that are hard to name probably are poorly designed suggests that this is not a good solution.</p>

<p>So, I have recently started splitting the data access into FooWriter and FooReader, which leads to nicer names and gives some additional flexibility, but at the same time I kind of like keeping it together, if the classes are not to big.</p>

<p>Is a reader/writer separation a better design, or should I combine them? If I should combine them, what the heck should I name the class?</p>

<p>Thanks /Erik</p>

[{'answer_id': 29574, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': 3, 'selected': True, 'text': '<p>ORM might be your best solution.<br>\nOr use a repository type pattern, with a "thingContext" object that is responsible for state persistence.</p>\n\n<p>Personally, I use the activeRecord pattern, where save logic is baked into a base class, but I\'m leaving it in favor of an nHibernate style repository pattern. The allowance for DDD and testing things without a db is very nice to have in a framework type situation, where my business logic is now gaining traction for a new UI.</p>\n'}, {'answer_id': 29577, 'author': 'Yaakov Ellis', 'author_id': 51, 'author_profile': 'https://Stackoverflow.com/users/51', 'pm_score': 2, 'selected': False, 'text': '<p>I am now using Linq to Sql. This solves the problem entirely.</p>\n\n<p>However if you do not have that option (or some similar ORM tool), I don\'t see any reason to separate Read/Write methods. It just adds more classes and complicates data access. I have always designed it as follows:</p>\n\n<ol>\n<li>Component/Business Object: Car</li>\n<li>Data Access, containing static Read and Write methods: CarDB</li>\n</ol>\n\n<p>Example Usage:</p>\n\n<pre><code>Car car = new Car();\ncar.Manufacturer = "Toyota"\ncar.Model = "Camry"\ncar.Year = 2006;\ncar.CarID = CarDB.InsertCar(car)\ncar.OwnerID = 2;\nCarDB.UpdateCar(car);\n</code></pre>\n\n<p>This also makes sense for data access where both Reads and Write need to be performed as part of the same transaction. If you split up the classes, where would that go?</p>\n'}, {'answer_id': 29732, 'author': 'Phil Bennett', 'author_id': 2995, 'author_profile': 'https://Stackoverflow.com/users/2995', 'pm_score': 2, 'selected': False, 'text': "<p>Ignoring ORM (not because I'm either for or against it) I would keep them in the same class.  They are both facets of a single responsibility and separating them just makes you look in two places where I can't really think of a good reason you would want to do that.  </p>\n"}, {'answer_id': 180928, 'author': 'Greg Dean', 'author_id': 1200558, 'author_profile': 'https://Stackoverflow.com/users/1200558', 'pm_score': 0, 'selected': False, 'text': '<p>When given the choice I generally subclass the reader to create the writer.  </p>\n'}, {'answer_id': 16376198, 'author': 'Sean', 'author_id': 1175459, 'author_profile': 'https://Stackoverflow.com/users/1175459', 'pm_score': 2, 'selected': False, 'text': '<p>Something that reads and writes to a backend store could be called a data accessor, or ReaderWriter, or IO, or Store.</p>\n\n<p>So how about one of:</p>\n\n<ul>\n<li>FooDataAccessor</li>\n<li>FooAccessor</li>\n<li>FooReaderWriter</li>\n<li>FooRW</li>\n<li>FooIO</li>\n<li>FooStore</li>\n<li>FooStorage</li>\n</ul>\n'}]
['https://Stackoverflow.com/questions/29558', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/276/']