learning_go/100_errors_go/interfaces/main.go
Alexander Pivkin 95f257a4d0 sdf
2026-01-23 14:36:31 +03:00

73 lines
951 B
Go

package main
BAD
// Producer
type CustomerStorage interface {
StoreCustomer(customer string) error
GetCustomer(is string) error
UpdateCustomer(customer string) error
GetAllCustomers() ([]string,error)
GetCustomerWithoutContract() ([]string,error)
}
//======================================
// Consumer
type customerGetter interface {
GetAllCustomers() ([]string,error)
}
//===================================================================
type IntConfig struct {
// ...
}
func (c IntConfig) Get() int { <======== PRODUCER
return 0
}
func (c IntConfig) Set(value int) {
//...
}
Consumer
type confifSetter interface{
Set()
}
type configGetter interface {
Get() int
}
type Mixed interface {
confifSetter
configGetter
}
type Foo struct {
threshold configGetter
}
func NewFoo(new_threshold configGetter) Foo {
return Foo{threshold: new_threshold}
}
func (f Foo) Bar() {
threshold := f.threshold.Get()
}