Am Freitag, 21. August 2015 07:45:09 UTC+2 schrieb ChrisLu:
Hi, I need some help to find the best way to deal with inheritance and
method chaining.

Let's say there is struct A, and struct B embed A as Golang's way for
Design-wise embedding in Go corresponds to delegation. Inheritance is
really a different thing, which is explained here
To understand the point you need to read the blog till you reach the
underlined phrase "What's that? Well, foo.MoreMagic() prints "base magic
base magic". In a language that supports inheritance (e.g. method
overrwriting) "foo magic foo magic" would be printed to the console.".

And A have method chaining to call a.Foo().Bar(), or a.Bar().Foo(). All
works as expected.


But if B wants to override one function Foo(), b.Foo().Bar() and
b.Bar().Foo() will not work as it looks, since b.Bar() will return *A.

So how can I the override the parent function without mirroring all
functions or implement the same thing twice via interface?
You can mimic this in Go as explained here

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

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 4 | next ›
Discussion Overview
groupgolang-nuts @
postedAug 21, '15 at 5:45a
activeAug 21, '15 at 1:49p



site design / logo © 2022 Grokbase