• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java application: architectural choices  RSS feed

 
Geane Norm
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have been trying to put together an application that 1) reads a number of zip files (XML) from a specific directory 2) unzip them into another directory 3)subset the content of the files by filtering out some of the tags/values 4)establishes a connection to a MongoDB instance and inserts the files into an existing collection. I am OK with each of the steps from an implementation point of view, what I am not sure about (and this is because I consider myself quite junior still) is how to divide the various functionalities into different classes. The way I see it, I should have one class that does 1 - 3 and another that deals with connecting to the MongoDB instance, get the DB/Collection, insert the files with some exception handling. What is your view? Does it sound sensible?

Thank you for your help,

I.
 
Peter Muster
Ranch Hand
Posts: 74
5
Eclipse IDE Python Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Geane Norm wrote:Hi,
I have been trying to put together an application that 1) reads a number of zip files (XML) from a specific directory 2) unzip them into another directory 3)subset the content of the files by filtering out some of the tags/values 4)establishes a connection to a MongoDB instance and inserts the files into an existing collection. I am OK with each of the steps from an implementation point of view, what I am not sure about (and this is because I consider myself quite junior still) is how to divide the various functionalities into different classes. The way I see it, I should have one class that does 1 - 3 and another that deals with connecting to the MongoDB instance, get the DB/Collection, insert the files with some exception handling. What is your view? Does it sound sensible?

Thank you for your help,

I.

Your application sounds more like a script or does it have a frontend?

I would always separate Model, View and Control unless your application is just a script in which case I personally would use Python instead of Java because scripting in a 100% object oriented language always looks weird to me. ;-) Your design will also depend on some factors. Would you reuse parts of the application for other projects or is it a one time thing? Is your application going to be expanded in the future or will it most certainly only do this one thing ever?

Just to give you some ideas
- One class could provide connection to the database
- One class could extract a given zip file
- One class could extract the XML content into one or multiple model classes (depending on what is in the files)
- One class acts as the controller:
1.) it invokes the DBHandler class to establish connection to the database
2.) it invokes the ZipHandler class to extract a set of files
3.) it invokes the XmlHandler class to parse the XmlContent
4.) it invokes the DBHandler or a separate DB class to pass the model objects that the XmlHandler returned from reading the xml files to it and have the DB class persist them in your database

The level of abstraction and separation would really depend on how reusable and flexible your code should be.
 
Geane Norm
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, thank you so much for your reply, it all makes a lot of sense indeed. I agree with you when you say that it sounds more like a job for a script and in that sense I ended up writing (for different purposes) a Groovy script that makes use of the XMLSlurper API to transform some XML files into JSON and import them into MongoDB. I must say that Groovy is actually pretty good, do you think it would be a good choice for my needs?

Thank you,

I.

Christian Pflug wrote:
Geane Norm wrote:Hi,
I have been trying to put together an application that . . .
. . .
The level of abstraction and separation would really depend on how reusable and flexible your code should be.


 
Peter Muster
Ranch Hand
Posts: 74
5
Eclipse IDE Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi and sorry for the late response.

I have no practical experience with Groovy. I haven't been scripting lately and at my former employer Python was the language of choice which I find very elegant.

Assuming we can trust Wikipedia it is syntactically similar to Python which I like. It appears to be a modern and living language and it uses the Java Runtime (so you wouldn't need to install a separate runtime on a system already running Java). It seems like a good choice to me.

Geane Norm wrote:Hi, thank you so much for your reply, it all makes a lot of sense indeed. I agree with you when you say that it sounds more like a job for a script and in that sense I ended up writing (for different purposes) a Groovy script that makes use of the XMLSlurper API to transform some XML files into JSON and import them into MongoDB. I must say that Groovy is actually pretty good, do you think it would be a good choice for my needs?

Thank you,

I.
 
Geane Norm
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christian Pflugradt wrote:Hi and sorry for the late response.

I have no practical experience with Groovy. I haven't been scripting lately and at my former employer Python was the language of choice which I find very elegant.

Assuming we can trust Wikipedia it is syntactically similar to Python which I like. It appears to be a modern and living language and it uses the Java Runtime (so you wouldn't need to install a separate runtime on a system already running Java). It seems like a good choice to me.

Geane Norm wrote:Hi, thank you so much for your reply, it all makes a lot of sense indeed. I agree with you when you say that it sounds more like a job for a script and in that sense I ended up writing (for different purposes) a Groovy script that makes use of the XMLSlurper API to transform some XML files into JSON and import them into MongoDB. I must say that Groovy is actually pretty good, do you think it would be a good choice for my needs?

Thank you,

I.


No probs Christian, thanks for your reply. Yes, I myself have no prior experience of Groovy, but I am slowly getting to know the language and it seems pretty suited for this task.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!