Where to put data read from file.

60 views
Skip to first unread message

vivek poddar

unread,
Jul 31, 2016, 9:04:10 AM7/31/16
to Clean Code Discussion
Hi,

I am trying a toy project to generate random quotes, to get up and running I am thinking to have a set of quotes in a json file later on it may be anything from DB to network. I don't to get into details hence I am thinking to have a repository object that would handle all the incoming and outgoing data.

That said, for now the repository would be responsible to read the JSON file and hand it over to its client.

Is this a good strategy so far?

PS: I am using GSON to read the JSON file.

vivek poddar

unread,
Jul 31, 2016, 9:07:15 AM7/31/16
to Clean Code Discussion
One thing I forgot :p where to put that JSON file?

Stefan Bradl

unread,
Aug 1, 2016, 2:00:58 AM8/1/16
to Clean Code Discussion
Yeah, that is exactly what a repository/gateway is for. Later on you just swap it out for your real DB gateway.

As for the framework (GSON): Frameworks should be kept at arms length. So it could be a good idea to define an interface for reading json files and write an GSON-Adapter which implements it. But that is not a must have. It may just be a good idea because you have no influence on the development of 3rd-party frameworks and so you should be able to change to other frameworks if needed.

vivek poddar

unread,
Aug 1, 2016, 2:03:22 AM8/1/16
to clean-code...@googlegroups.com

--
The only way to go fast is to go well.
---
You received this message because you are subscribed to the Google Groups "Clean Code Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clean-code-discu...@googlegroups.com.
To post to this group, send email to clean-code...@googlegroups.com.
Visit this group at https://groups.google.com/group/clean-code-discussion.

Reply all
Reply to author
Forward
0 new messages