4 ms·
Say you have: Reader - an interface for reading stuff Writer - an interface for writing stuff Some things implement Reader and some things implement Writer. S
by jlouis 14y ago
Say you have:
Reader - an interface for reading stuff
Writer - an interface for writing stuff
Some things implement Reader and some things implement Writer. Some things implements both. Now you can declare ReadWriter as in
http://golang.org/pkg/io/#ReadWriter http://golang.org/pkg/io/#ReadWriter
and everything implementing both will automatically be a member of this newly formed interface. You don't have to go back and tag an "implements ReadWriter" on each of the things you want to implement it. The implementation is implicit if you obey both interfaces.
The power is that you can change your interface structure later on in another part of the program, and the existing code just picks it up. You may not even have the source code , or the right to change the source code, so you can't easily tag an 'implements ...' on top of it.