Assume a public interface I with two methods NotInS and M whereas NotInS is calling M. An implementation i of I which implements NotInS and M as well as a specialization s of i which only implements M. Finally a constructor whose return-type is I returns a pointer to an instance of s. Calling on this return-value NotInS will execute i.M() as the following test shows. I would like it to call s.M(). How would I do this in a goish way? Thanks for any help!

package main

import (
        "fmt"
)

type I interface {
        NotInS()
        M()
}

type i struct{}

func (_i *i) NotInS() {
        _i.M()
}

func (_i *i) M() {
        fmt.Println("i")
}

type s struct{ *i }

func (_s *s) M() {
        fmt.Println("s")
}

func newI() I {
        return &s{&i{}}
}

func main() {
        _i := newI()
        _i.NotInS() // prints i instead of s
}

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/fb4e1386-4c24-6486-58b3-93dd07e46259%40gmail.com.

Reply via email to