jung-kurt / gofpdf

A PDF document generator with high level support for text, drawing and images
http://godoc.org/github.com/jung-kurt/gofpdf
MIT License
4.34k stars 786 forks source link

Use Pdf Template #213

Open d1ngd0 opened 5 years ago

d1ngd0 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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”).