FAQ

On Thursday, December 19, 2013 5:35:31 AM UTC-7, Kai Noda wrote:

"All known implementing structs"

It's easy to mistake structs as Go's version of a class (even if you aren't
thinking about it in those terms), since both classes in other languages
and structs in Go have members with visibility rules. However, structs
aren't special in Go, and don't "do" anything (methods are about behaviors)
that any other kind of type can't do equally well; *any* named type (even
something derived from an int, for example) can have methods, and any type
can be the basis for a named type. In Go, there's no equivalent to the
distinction other languages make between a class and a primitive, since all
Go types consistently have the same properties related to (Go's flavor of)
object orientation. Also, there's no abstract 'object' type (no
super-base-type) in Go -- we really don't care much about hierarchies, so
we don't have them.

P.S., while embedding may seem special, and out of the concrete type kinds
is limited to just structs, it doesn't make structs special or class-like.
The struct type kind wasn't created to support embedding (the concept of a
struct is already useful on its own), but rather, embedding is simply a
natural consequence of the properties of structs (which [can] contain
multiple heterogeneous fields) and interfaces (which [can] contain multiple
heterogeneous method signatures).
On Thursday, December 19, 2013 8:27:24 AM UTC-7, Jsor wrote:

Do remember that just because it satisfies an interface doesn't mean it...
satisfies an interface.
True, but we need a different term for that. To be precise, any successful
assignment of any value x to a given interface T means that, as far as the
language and runtime are concerned, x implements T. What goes beyond the
strict concept of interface implementation is the concept of semantics,
which can be partially addressed with use of named types (if you provide
the type and the interface, it's unlikely that someone will define an
implementing type according to the wrong semantics).

--
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/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 8 of 8 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 19, '13 at 12:35p
activeDec 19, '13 at 8:17p
posts8
users6
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase