Slide 1

Slide 1 text

OOP in Go Familiar but Different

Slide 2

Slide 2 text

About Me Johnny Boursiquot Principal Software Engineer 
 @ RBM T echnologies @jboursiquot on T witter, GitHub, etc Programing language enthusiast

Slide 3

Slide 3 text

About this talk Beginner to Intermediate level Basic understanding of OOP from another language for context Some familiarity with Go syntax expected but not mandatory

Slide 4

Slide 4 text

What we’ll cover What is OOP anyway? How does Go differ? What does OOP look and feel like in Go? Q&A

Slide 5

Slide 5 text

What is OOP anyway?

Slide 6

Slide 6 text

OOP OOP tends to model concepts as “objects” that interact with other objects within the world of your program Most are familiar with class-based OOP Java, C++, Objective-C, Ruby, Python and others, all embrace class-based OO

Slide 7

Slide 7 text

OOP “Objects” have both data (state) and behavior (code, often called “methods”) Behaviors access and often modify object state Objects tend to have the notion of “self” or “this”

Slide 8

Slide 8 text

OOP “Objects” represent “instances” of “classes” in common OO languages Class-based orientation commonly includes Inheritance and Polymorphism OO programmers have come to favor composition over inheritance

Slide 9

Slide 9 text

How does Go differ?

Slide 10

Slide 10 text

T ypes and values rather than “classes” and “objects”

Slide 11

Slide 11 text

// data http://play.golang.org/p/Mz3rqyIRO7

Slide 12

Slide 12 text

// behavior (on types) http://play.golang.org/p/7wo-feyESu

Slide 13

Slide 13 text

// behavior (on any type) http://play.golang.org/p/lvTRl2fYhh

Slide 14

Slide 14 text

Composition over Inheritance

Slide 15

Slide 15 text

Composition (Embedding) http://play.golang.org/p/ZZmeDoeMgi

Slide 16

Slide 16 text

Composition & Anonymous field method access http://play.golang.org/p/XIepDulSMp

Slide 17

Slide 17 text

Anonymous field types do not enable Sub-Classing http://play.golang.org/p/Bw8HcUBfSm

Slide 18

Slide 18 text

Polymorphism through Interfaces

Slide 19

Slide 19 text

Interface T ype http://play.golang.org/p/3BxLmc36q_

Slide 20

Slide 20 text

In a Nutshell Go has types and values rather than classes and objects Go provides many of the same features we're used to in classical- orientated languages: methods on any type automatic message delegation through embedding polymorphism through interfaces Go does not have inheritance, no "is-a" relationships between objects Go relies on composition for OO

Slide 21

Slide 21 text

Program in Go
 in the “Go Way”

Slide 22

Slide 22 text

Go-related https://www.youtube.com/watch?v=HqZQBmNVhBw http://spf13.com/post/is-go-object-oriented/ http://nathany.com/good/ https://www.youtube.com/watch?v=B-r3Wf_I2Lk http://www.goinggo.net/2014/05/methods-interfaces-and-embedded-types.html http://jordanorelli.com/post/32665860244/how-to-use-interfaces-in-go OOP in general: http://www.artima.com/lejava/articles/designprinciples.html http://en.wikipedia.org/wiki/Object-oriented_programming http://en.wikipedia.org/wiki/Composition_over_inheritance http://en.wikipedia.org/wiki/Polymorphism_(computer_science) http://en.wikipedia.org/wiki/Polymorphism_(computer_science) http://en.wikipedia.org/wiki/Class-based_programming Resources

Slide 23

Slide 23 text

Thanks!
 Q & A
 @jboursiquot