3

I have one design issue and can't seem to find a good answer by my own. I am required to build application with some specific features which doesn't really matter because I implemented most of its business logic and behaviour. My problem is that at some point, this applications needs to read some data from the database and made a decision upon that data what it needs to do next (it is not nothing special just some checking and so on). The real problem is that I don't have the actual database schema and think that it would be a waste of time if I would go on and create my own model based on some json and classes I have. The real deal is that I would like to somehow simulate communication with database with some layer, but at the same time not using hardcoded list of data. Is there some good way to achieve it with good cohesion so that someone could later plug database to my app.

Thanks in advance!

  • How do you read from the database if you don't know what's its schema? – Vincent Savard Nov 24 '16 at 16:24
  • 1
    Have you looked into using mocks for unit testing along with how to build a data access layer that can easily have the database type changed? – JeffO Nov 24 '16 at 16:25
  • By hard coded data, do you mean data in a code file or are you also trying to avoid reading from a text file, spreadsheet, etc.? – JeffO Nov 24 '16 at 16:26
  • I need to do only core features of an application because I work remote part time for a company so they'll do all gluing to they external sources. But my responsibility is to also implement behaviour based on data from database which I don't have and I wouldn't want to give them some half-finished I made it like that to work job. – mpisacic Nov 24 '16 at 16:51
  • In that case, you could mock classes in your DAL to unit test your program, but if you wanted to integration-test it, you'd need to access the database. Either you ask your company to provide you a connection to a database that you can freely use (i.e. drop all data and recreate it every time you run your tests) or you ask them to provide the schema so you can run, create and populate the data on the fly. To be honest, if I were in your case, I'd definitely ask for the schema as I couldn't consider the project finished before the integration tests are working, which requires an actual DB. – Vincent Savard Nov 24 '16 at 17:26
6

Use the repository pattern and a mock repository with hard coded data.

This will minimise the amount of work you have to put in to your guesswork and thus the amount of rework required when you get the actual database schema

  • I think that would be my option after all without much unnecessary complexity. Thanks for your answer! – mpisacic Nov 24 '16 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.