The following is what the SOLID acronym initials stand for:
Single responsibility
Open/Closed
Liskov substitution
Interface segregation
Dependency inversion
The code conflates two responsibilities: retrieving/mutating the state of a document and creating a signature for the document's content. Furthermore, the proposed implementation is inflexible as it forces the use of a specific signing algorithm. To address this problem, we can remove theSignmethod from theDocumenttype and provide an external helper that can sign not only instances ofDocumentbut also any type that can export its content as a string:
type ContentProvider interface {
Content() string
}
type ECDADocumentSigner struct {//...}func (s ECDADocumentSigner) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.