Interfaces in Go

50 %
50 %
Information about Interfaces in Go

Published on February 28, 2014

Author: MattSelf



Interfaces in Go (Golang): Preparing for Change. Presented at Denver Gopher Meetup on 2.27.14.

Interfaces in Go Preparing for Change

Matt Self @_m4tty

"We demand rigidly defined areas of doubt and uncertainty!" - The Hitchhiker’s Guide to the Galaxy

What is an Interface? An access view that separates the What from the How The What is our defined entry point The How is the details that we wish to hide We hide our internal implementation (the How) by allowing access only through a well defined entry point (the What).

Protected Variation “Identify points of predicted variation and create a stable interface around them.” - Alistair Cockburn “We propose instead that one begins with a list of difficult design decisions or design decisions which are likely to change.” - David Parnas Craig Larman - Protected Variation: The Importance of Being Closed David Parnas - On Criteria to Be Used in Decomposing Systems into Modules

Interfaces in Go? A custom type that specifies a group of method signatures Checked at compile time, but dynamic when needed Duck typing. No “implements” needed. Allows for emerging design. type Animal interface { Run() }

And what is this interface{} thing? The interface{} type is a interface that specifies no methods type interface interface {} This type can be used for any value, because all values meet this interface. Remember “dynamic when needed”...

Interface values Runtime computed (and cached) method tables interface table (Animal, Gopher) type Gopher fn[0] (Gopher).Run var a Animal = Gopher{} A function pointer to gopher Run a.table Gopher data Calling a.Run() causes Go compiler to generate code that does: a.table -> fn[0] Checking the type (i.e. v, a.table -> type ok := a.(type) ) does:

Embedding Embedding interfaces type Animal interface { Run() } type Monkey interface { Animal Swing() } Embedding types, or “delegating” will meet interface specification if embedded type meets specification.

Real-ish World Example : PubCloud An over abstracted example, in order to highlight interface usage.


So long and thanks for all the fish!

Add a comment

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...

Related pages

Go by Example: Interfaces

To implement an interface in Go, we just need to implement all the methods in the interface. Here we implement geometry on rects.
Read more

GoLang Tutorials: Interfaces in Go

Interfaces are contracts that exist between an expected implementation of a functionality and its actual implementation. In real life there are ...
Read more

Interfaces in Go -

Interfaces in Go 2015 Aug 25. Interfaces are a straight-forward way to decouple behavior from implementation. This post shows how to create reusable tests ...
Read more

What Is an Interface? (The Java™ Tutorials > Learning the ...

What Is an Interface? ... Interfaces form a contract between the class and the outside world, and this contract is enforced at build time by the compiler.
Read more

How to use interfaces in Go - Jordan Orelli

How to use interfaces in Go Before I started programming Go, I was doing most of my work with Python. As a Python programmer, I found that learning to use ...
Read more

Interfaces in Go: Object Oriented Go - Medium

Interfaces in Go Object Oriented Go. Object Oriented Programming is a programming paradigm in which code is organized into objects, abstract ...
Read more

Protocol (object-oriented programming) - Wikipedia

If the objects are fully encapsulated then the protocol will ... The object-oriented features in Perl also support interfaces. Although the Go ...
Read more

Interfaces: INFORMS

About Interfaces. The mission of Interfaces is to publish manuscripts focusing on the practice of operations research and management science and the impact ...
Read more

MSDN - Interfaces (C# Programming Guide)

An interface contains definitions for a group of related functionalities that a class or a struct can implement. By using interfaces, you can, for example ...
Read more

Wireshark · Go Deep.

Go Beyond With Riverbed Technology. About Wireshark ... Wireshark development thrives thanks to the contributions of networking experts across the globe.
Read more