문제가 없다. 한 세트의 사용자 코드는 이러한 메서드를 신경 쓰지 않을 수 있지만, 다른 세트
는 신경을 쓸 수 있다. 예를 들어,
io
.
File
타입은
io
.
Writer
인터페이스도 만족한다. 코드
가 파일을 읽는 것만 신경을 썼다면, 파일 인스턴스를 참조하기 위해
io
.
Reader
인터페이스만
사용하여 다른 메서드는 무시할 수 있다.
7.7
임베딩과 인터페이스
구조체에 타입을 임베딩 할 수 있는 것처럼, 인터페이스에 인터페이스를 임베딩 할 수 있다. 예
를 들어,
io
.
ReadCloser
인터페이스는
io
.
Reader
와
io
.
Closer
로 구성된다.
type Reader interface {
Read(p []byte) (n int, err error)
}
type Closer interface {
Close() error
}
type ReadCloser interface {
Reader
Closer
}
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.