interface-package example
The same example as the previous example but the interface and methods
placed in a package.
This example is based on the previous example
interface.
GitHub Webpage
THE BOTTOM LINE
This is exactly the same as the previous example except I am using a package.
This makes the beauty of the interface come out, since we just make
the interface and use the interface. Everything is hidden in the
package except for the following,
- type MyInterfacer interface {
- func MakemyStructA(name string) MyInterfacer {
- func MakemyStructB(x, y int) MyInterfacer {
- func Magic(i MyInterfacer) {
As you can see it makes things easy.
I did add one thing, the ability to update the data for StructA.
- func UpdateName(i MyInterfacer, name string) {
RUN
go run interface-package.go