backend_queue.go
// BackendQueue represents the behavior for the secondary message
// storage system
type BackendQueue interface {
Put([]byte) error
ReadChan() chan []byte // this is expected to be an *unbuffered* channel
Close() error
Delete() error
Depth() int64
Empty() error
}
类是对数据和方法的抽象和封装,那么接口就是对类的抽象。
使用接口的好处是非常灵活,这样就与具体的实现做了解耦,如果以后有其他的实现类,只需要实现接口就可以了,而不用去改使用的时候的代码。