views:

284

answers:

3

I have certain objects in my domain which are not aggregate roots/entities, yet I still need to retrieve them from a database. I don't want to confuse things by creating repositories for these things. So, what are alternative data access patterns? Would you simply create a DAO for them, while still of course separating the interface?

Edit:

Some more detail on what I'm doing. I need to create a code. This code has certain rules as to its format. One of the rules is that the final character must be a unique number incremented by one from the last code generated. For example:

ABCD1 ABCD2 ABCD3

So, I'm keeping a table with one row, one column to store the number in question. Now, I don't want to consider this number an entity and create a repository for it - that's overkill. I just need a way of retrieving the number, adding 1 to it, and saving it. I know there are myriad ways I could do it, but I'm wondering if there's an customary way.

+1  A: 

There are several data access patterns that could apply, in theory. You'd need to provide more detail though if you want us to suggest a specific pattern.

Without more detail, all I can suggest is to consider looking into Martin Fowler's Patterns of Enterprise Application Architecture book.

Edit: Customary way? No, not that I can think of - it really depends on where and how you're using this unique code in your domain. If I were doing this, I'd probably create a small service that speaks directly to the database to perform this function - not as heavy-weight as a repository, and very focused on the problem at hand.

Erik Forbes
A: 

Based on the edit: I would look first at the context in which you need to create that code. Perhaps there are some related entities or something that you are missing.

btw, I find the question really interesting as it comes up from time to time while coding specific features. I usually end up finding I was missing something on the scenario and it ends up fitting well with the normal repository pattern.

eglasius
A: 

After surveying the options I'm going with the Table Gateway pattern.

bingle
@NG - to make your answer more useful to those that come across the answer in the future can you provide a summary of this pattern? possibly link(s) to articles about this pattern?
Maslow