Question

I have a school project where we must apply some design patterns in java code. I have to make a functionality where data is obtained by JPA/Hibernate and present it in a pdf or excel. I need to make it so that multiple file extensions can be added in the future.

My question is, what design pattern is best used for a pdf/excel report builder like this.

The design patterns I've already looked at is the strategy pattern and the factory pattern(standard, method and abstract).

Was it helpful?

Solution 2

Take a look at the MVC Pattern

It might be suited to your requirements, I would have a different view for PDF and EXCEL files. As you add new file types you could add a new view to handle each of them.

The Controller is the link between your user input and the system, it might take a selection from you for the view you wish to see.

The Model is essentially the data you wish to present in your reports. This should be the same for the pdf or excel report.

The View will be either an excel view which creates the excel file, or a pdf view which creates the pdf file. Both use the model as input.

Assumption you have a user interface.

OTHER TIPS

As the question is stated, I suppose you should consider some of the creational patterns. Factory would probably be the best way to implement the specific functionality.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top