I am still trying to understand Golang interface. Please correct me and help me understand.
Frances Campoy explains, interface
is a set of contraints.
So in my case, let's say I have one Store
interface that is to be interfaced with contrains, like sort Interface
in Go.
type Store interface {
Earning() int
Expense() int
}
Then what do I have to do if I want to implement this interface constraint to other packages like StoreA
, StoreB
? I want to get a message like when I try:
aa := StoreC{}
aa.Add("AAA")
// error saying `StoreC` does not implement method `Add`, constrained by interface `Store`... something
So what do I do if I want to enforce this contraint in other Store
s? Do I need to do something like inheritance?
type StoreC interface {
Store
}
In other words, I wonder how package sort
's interface of 3 methods can be enforced to every sort
operations in Go. How does it enforce the contraints to any other possible sort
uses in Go?
Thanks!