inheritance-interface-narrow

command module
v0.0.0-...-f200d43 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

README

Inheritance w/ Narrowing Interface

This example attempts to demonstrate two interfaces where the child interface overrides a method in the parent to return a more narrowed type.

... Not directly possible.

And, it turns out that it does not appear possible to override a method and narrow the method's signature in a child interface.

It is possible to "inherit" a parent interface (Animal in this example) into a child interface (Cat) and in the child interface define a similar, but named differently, method that does return the narrowed type. And then, simply define the wider method (Say()) to invoke and return the narrower method and type (CatSay()).

I'm not sure that does a whole lot to improve readability however. ... hummm.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL