Downside with this is it implies doing copy/pasting and maintaining
duplicate code. If PrepareAndAttack would contain complex logic other than
a simple print, that will certainly lead to an un-maintainable mess

Julien Semaan

On 30 January 2017 at 11:40, <ra2...@gmail.com> wrote:

> Parent struct methods get the receiver of parent, and cannot refer to
> child.
> Try https://play.golang.org/p/fi3T_Z95O8
>
>
> On Monday, January 30, 2017 at 9:31:15 PM UTC+5:30, jul.s...@gmail.com
> wrote:
>>
>> Hi,
>>
>> Where I work, we are currently experimenting with golang in order to
>> migrate our existing Perl codebase to golang.
>>
>> Although Perl isn't a pure OO language, it allows for a lot of the OO
>> patterns to be used. One of the patterns we do use is where a superclass
>> method wraps a series of call to other methods that can be overloaded by
>> subclasses.
>>
>> Here is an example of what I mean:
>> https://goo.gl/hTnUI4
>>
>> Now, I've tried to apply the same principle in golang but failed as the
>> method attack isn't called on the right type:
>> https://play.golang.org/p/ZHhaQhSrms
>>
>> I've scratched my head for a bit to find a solution for this, and the
>> idea I found was to wrap the prep+attack call in a function that isn't tied
>> to any of the two structs
>> https://play.golang.org/p/7nK8xEV5rj
>>
>> The example above creates the behaviour I initially expected but I don't
>> find its as clean as when using the classic OO pattern.
>>
>> Now my question is, how do people usually translate this classic OO
>> pattern into golang other than the way I found ?
>>
>> Thanks !
>>
>> - Julien
>>
>

-- 
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