mardi 6 octobre 2020

Hexagonal Pattern: how to manipulate data

I've previously created a really simple app where I can generate PDFs from data. However It has come to my attention that my application didn't respect the most basic design pattern.

My code was basically fetching data from my model(could fetch data from different sources, so it never has the same shape) and passing as parameter the retrieved object to my "pluging-class" generating a PDF from this data. (PDF always look the same)

My problem is that if I want to create different types of PDFs then I need to create a lot of methods which are all looking alike, but using differents objects as parameters [![see this image][1]][1] [1]: https://ift.tt/30Eb63L

So I'm wondering if it's wrong considering my PDF generator as a plugin and if I should just move it elsewhere in my code. Or if I should make a factory of PDFGenerator(which I tried and doesn't seem to work) or another design pattern?

I just don't understand how I could make my "PDF plugin" generic because it's always using different type of data to create its content.

I hope I've been clear.

Aucun commentaire:

Enregistrer un commentaire