0

I have a list of report types (objects) in the database that need to be generated for the user and sent out by email / printed / saved on hdd etc.

One report ('skeleton') is one row in database.

My question is: should I create a separate object for query result of one row - 'skeleton' report object and then use this object to create the end 'report' object. Is this the correct way of handling such task?

I have been told that it is easier to create a method and just get a rowset from the database in it. Then parse the row set for required parameters necessary to create the report, create the end report object and etc.

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
Deniss M.
  • 3,617
  • 17
  • 52
  • 100

1 Answers1

1

I am not totally sure if I understand your question correctly, but I assume that you want to know if you should fill an object with the data from the database and parse the object when creating the report or just pass the resultset to the creation method?

I would recommend using an object 'Skeleton' and filling this one, since you can reuse it later on and it makes the code way more readable in my opinion.

More information on this toppic: In many applications the MVC pattern is used to structure your program. In this pattern you structure your program in 3 layers, the first one for your UI(VIEW), the second for you buisness logic(Controller) and the third one for your persistence data(Model). These layers only communicate through domain model objects which represent your data (in your case this would be the 'Skeleton' object, also called POJOs ). This is especially helpful if you suddenly want to change from a database to a textfile or any other persistence strategy, since you should only have to change the model layer while keeping the other layers mostly the same (especially if you're using interfaces). You can find a lot on this pattern in the internet and for most standard applications i would definitely recommend it

LuckAss
  • 114
  • 7
  • Thanks for your answer, you understood correctly. I am planning on using the factory pattern for the process of generating different types of reports and a repository pattern for working with data collections needed for filling the report object. – Deniss M. Aug 18 '16 at 06:16
  • 1
    ahh ok, in this case you should still use a special 'Skeleton' object since it's just way more readable and probably easier to use in your factories – LuckAss Aug 18 '16 at 08:54
  • the question is now should that skeleton object be reusable as the main object, or should it be just used to gather data for the main object. :) sorry if it is stated in a complicated way. – Deniss M. Aug 18 '16 at 08:57
  • 1
    it depends on what you would want to do with it. it's best practice to use these domain objects only for data storage, so there are only the properties, getters, setters and standard methods like toString() etc. You shouldn't use the Skeleton object for buisness logic, but you can actually reuse it wherever it's needed. Just make sure to keep some logic, for example if you have 2 different tables in your database, these should have different objects, even if their fields have the same types except for the names, this way you won't loose track on which one you're currently working – LuckAss Aug 18 '16 at 09:02