The answer depend on details which is not mentioned in the question.
It will depend on the exact details of D1, D2, ..., A1, A2. Such detail may not be worthwhile to mention in your question, because it will make the question too localized, and few will read all of the details. It may still help to get a more tailored answer.
If you find my answer too simplistic, you should be adding more detail to your question.
How much code could be shared between each type of data handler?
It depends on how much commonality exists between each type of data. By commonality I mean the similarity in structure, or sub-structure.
For example, given that
- Each
PersonContactInfo
contains one or more TelephoneContact
record.
- Each
BusinessDepartmentContactInfo
(also) contains one or more TelephoneContact
record.
Then, if there is any code to be written for the TelephoneContact
record, it can be reused between the two or more classes that uses it.
By similarity in structure, what I mean is not similarity in values or statistical distribution. I can point you to a counterexample.
Code reuse is applicable to all programming paradigms. Some paradigms and programming languages have specific syntax and library features to help with code reuse.
Choosing a programming paradigm for your problem.
The decision of what programming paradigm to use should come after:
- You understand the size of data (order of magnitude) that you intend to handle.
- If you need to handle billions of data, you may need to consider alternative paradigms, such as data-oriented design, database, or distributed processing.
- You have a basic outline of what functionality needs to be in the software, but without going into too much detail.
- You have a outline / preliminary plan of how you want your software to be structured.
- You have identified the commonalities, as described above.
Deciding where to use POD (plain old data structure) or Objects.
If you have decided to use Java, it is recommended to use object-oriented design, as radarbob suggested above, because the advantage of using Java is lost if one do not take advantage of OOD.
It is assumed that you have finished with the Class-Responsibility-Collaborations step. In Object-oriented design, the result of CRC becomes your initial Java class design.
You can make further changes to your class design as you see fit, as in refactoring.
Writing code to read data from a file, and save results to a file.
There are many choices - so many that it is overwhelming.
- At the minimum, a data reader needs to be implemented for the dataset format that is used by D1, D2, D3 and D4.
- Java supports object serialization as part of its language.
- However, if the source code of the class is modified, previously serialized data cannot be deserialized anymore - it will be lost.
- Because this is a very prevalent issue, there are many solutions: (just to name a few)
Also, you may consider the following trade-off:
- Space efficient - take up as little disk space as possible - often means binary data and non-human-readable.
- Human-readable - use text as much as possible (XML or JSON), but which takes up more disk space
- Human-readable combined with standard compression, such as GZIP. This is a balanced approach between space and readability.
Should I use a database?
Unfortunately I do not have much experience with database. Other people can contribute ideas.