Maybe I misunderstood your need, but I would just call the A method
directly like below.
type A struct{}
func (a *A) private() {}
func (a *A) Public() {
a.private()
}
type B struct {A}
func (b *B) private() {
b.A.private()
}
bi := B{}
b.Public() //calls the A.Private
Le vendredi 1 septembre 2017 16:50:52 UTC+2, BeaT Adrian a écrit :
>
> Hello, I ran into a strange scenario and I wanted to know if there is a
> better solution for it
>
> type A struct{}
>
> func (a *A) private() {}
> func (a *A) Public() {
> a.private()
> }
>
> type B struct {A}
>
> func (b *B) private() {}
>
> bi := B{}
> b.Public() //calls the A.Private
>
>
>
> I just want to rewrite a small part of the algorithm.
> As a workaround I used composition, but in a weird way
> type A struct {
> private
> }
>
> func (a *A) Public() {
> if a.private == nil {
> //set private for A
> }
> a.private
> }
> type B struct {A}
> func (b *B) Public() {
> if b.private == nil {
> //set private for B
> }
> }
>
>
>
> Other solutions I tried were not effective (how to detect in inner A
> function that it's a B now, and should use other algorithm).
>
> Thanks!
>
>
>
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.