Entities & Interfaces
Defining Entities
Entities are defined as private structs (e.g., exampleImplementation
) embedding a DataObject. This keeps implementation details hidden and allows for generic data handling.
Public Interfaces
Public interfaces (e.g., ExampleInterface
) expose all necessary methods for interacting with the entity, enabling mocking, testing, and extension.
Example Code
type ExampleInterface interface {
ID() string
SetID(id string) ExampleInterface
// ... other getters/setters
Metas() (map[string]string, error)
SetMeta(key, value string) (ExampleInterface, error)
}
type exampleImplementation struct {
dataobject.DataObject
// ... other fields if needed
}