Hi,I know Go is not true OOP language, but is there any way for "base class" to call method of "derivated class" polyformically, just like C++ virtual methods?Thank you--
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...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Well, that is not what I am looking for. Let me show you a C++ program example:
As I am evaluating Go for a project of mine, I was wondering how one can implement some of the GoF patterns, namely:
http://sourcemaking.com/design_patterns/template_method
Tad, yes I want exactly " to define some/most of the behavior in a base class and then define the rest in derived classes".But your example doesn't do that. I think there is no machinery in Go for this at all.It is OK, this kind of functionality can be expressed in Derivated classes alone, but with code duplication I am afraid.
Tad, you example is ecvivalent to: http://play.golang.org/p/2_JSbYLSJnIf you though to call methodB() then the result is: http://play.golang.org/p/XeL-iHT9d2
--
On 07/05/2013 8:49 AM, <drago....@gmail.com> wrote:
>
> Tad, yes I want exactly " to define some/most of the behavior in a base class and then define the rest in derived classes".
Go doesn't have the concept of a base class so this is an impossible request.
Inheritance groups a number of features together, polymorphism and code reuse.
Go uses interfaces for polymorphism, and composition(embedding) and functions for code reuse.
Instead of defining a 'base class' define an interface and write a function that takes that interface value and does the concrete thing you want to do.
implement that interface for any type you want to be able to share that code with.
--
--
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...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Tad, yes I want exactly " to define some/most of the behavior in a base class and then define the rest in derived classes".But your example doesn't do that. I think there is no machinery in Go for this at all.
It is OK, this kind of functionality can be expressed in Derivated classes alone, but with code duplication I am afraid.