Skip to content
This repository has been archived by the owner on Nov 13, 2021. It is now read-only.

Use Pdf Template #213

Open
d1ngd0 opened this issue Dec 4, 2018 · 3 comments
Open

Use Pdf Template #213

d1ngd0 opened this issue Dec 4, 2018 · 3 comments

Comments

@d1ngd0
Copy link
Contributor

d1ngd0 commented Dec 4, 2018

Considering the interface type Pdf should have all of the methods that are defined in Fpdf (which also then automatically get added to Tpl) would it make sense to make Fpdf and Tpl un-exported types and return a Pdf interface instead? I feel like this could simplify things from a user perspective.

I do understand however that this would be a breaking change so you likely won't want to do it, but I figured opening up a discussion about it wouldn't hurt.

@jung-kurt
Copy link
Owner

Interesting thought. Would there be advantages to not exporting Fpdf and Tpl besides just information hiding? If not, maybe they could remain exported but we could still use the Pdf interface wherever possible. If I am not mistaken, doing this would not break anything.

@d1ngd0
Copy link
Contributor Author

d1ngd0 commented Dec 4, 2018

I may be wrong, but wouldn't something like this break?

var pdf *gofpdf.Fpdf
pdf = gofpdf.New(blah blah blah)

New would return a gofpdf.Pdf and not a *gofpdf.Fpdf so you would need to cast it to a Fpdf type

@jung-kurt
Copy link
Owner

I think New() would still return the concrete type *gofpdf.Fpdf and CreateTemplate() would still return *gofpdf.Tpl, but functions like StateGet(pdf *Fpdf) could be changed to StateGet(pdf Pdf). The idea would be to honor Postel's Law (in Go: “Accept interfaces, return structs”).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants