다음 방법으로 인터페이스에 연결된 메서드를 구현하는 것이 맞습니까? 유형은 인터페이스에 필요한 모든 것을 갖추고 명시 적으로 당신이 구현되어 있다고 할 필요가 없습니다 이동에서 (getKey
, getData
)인터페이스 방법
type reader interface {
getKey(ver uint) string
getData() string
}
type location struct {
reader
fileLocation string
err os.Error
}
func (self *location) getKey(ver uint) string {...}
func (self *location) getData() string {...}
func NewReader(fileLocation string) *location {
_location := new(location)
_location.fileLocation = fileLocation
return _location
}
사실 'reader'는 실제로 'location' 유형에 익명의 멤버를 추가하지 않고 아무것도 유용하지 않은 공간을 차지하지 않으십니까? – matthias