On Tue, Nov 22, 2016 at 4:29 PM, Seb Binet wrote:

>
>
> On Tue, Nov 22, 2016 at 10:16 PM, Tong Sun wrote:
>
>> Hi,
>>
>> How to architect the OO's virtual function in Go?
>>
>> Please take a look at this (not working) Go program
>> https://play.golang.org/p/qrBX6ScABp
>>
>> Please think of the "func Output()" as a very complicated function that I
>> only want to define *once *at the base level, not to duplicate into each
>> sub classes.
>>
>> How can I make it works so that the last output statement, instead of
>> being,
>>
>> fmt.Printf("[%v] %s: [%0.2f]\n", k, v.Name(), v.Area())
>>
>>
>> will be this instead:
>>
>> fmt.Printf("[%v] %s\n", k, v.Output())
>>
>>
> what about this:
>  https://play.golang.org/p/DdZBiOgF2w
>


Aha, that way. I've been banning my head for a while & you saved my day.
Thanks a lot!

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to