Hi,
I'm trying to refactor my data access code so that it's as clean as possible. Though I'm not looking to use MVC pattern in my project, I still want my code to be well organised and as of right now, I can't help but feel like it could be quite better. For now, I want to concentrate on everything related to data access in my code.
In the MVC pattern, the business layer talks to the data access layer which talks to the data store. (skipping the presentation part)
business talks to data access (game init)
data access talks to data store (repository request)
data store returns query to data access (database fetch)
data access builds object from query data (data mapping)
data access returns built object to business (repository return)
business works with object (gameplay)
Here is my current process:
business talks to data store
data store returns query to business
business gives query data to data mapper
data mapper returns built object to business
business works with object (gameplay)
In a pseudo code example, this is how I would build an archer entity:
init () {
/* Step 1 + 2: business talks to data store and data store returns query data */
XMLData archerXml = database.find_xml("entities/archer");
/* Step 3 + 4: business gives query data to data mapper data mapper returns built object to business */
Entity archer = data_mapper.map_entity(archerXml);
/* Step 5: work with object */
allEntities.add(archer);
}
update () {
/* Step 5: work with object */
for each (entity in allEntities) {
entity.update();
}
}
How do you handle data access in your games? Is there existing data access patterns for game programming?
↧