SlideShare a Scribd company logo
GoLang for OO Programmers
Khalid Nowaf COSC 419
Special Topic : Golang and Docker
Computer Science
Okanagan College, 2016
Before We Start
 Import The presentation Packages by using this Commands
 go get github.com/Khalid-Nowaf/goExample
 go get github.com/Khalid-Nowaf/animal
 go get github.com/Khalid-Nowaf/embedded
 You should find all the code in this path
 {GOPATH}/src/github.com/Khalid-Nowaf
 The goExample package include the main files for our examples, where animal and embedded
packages just the implementation
 You should run any file in goExample by using this command
 go run {filename}
 E.g. go run class.go
Agenda
 Struct Types ”As Class”
 Constructor and Custom Constructor “Factory”
 Private and Public Struct Members
 Embedded types (Composition)
 Shadowing Fields and Methods
 Interfaces
Is GoLang OO ?
 Classes
 Encapsulation
 Inheritance
 Interfaces
 Composition
 delegation
 Polymorphism
“ Objects are like people. They’re
living, breathing things that have
knowledge inside them about how to
do things and have memory inside
them so they can remember things.
And rather than interacting with
them at a very low level, you interact
with them at a very high level of
abstraction, like we’re doing right
here. “Steve Jobs
Classes
Fields Methods
From Khalid-Nowaf/animal/animal.go
Object
In Go there is no such thing called Objects , but there is Types !
How to use ”this” keyword in Go ?
Constructor
Go has Built-in Constructor, but limited.
From Khalid-Nowaf/animal/animal.go
Custom Constructor
To simulate the Constructor we create a method that return a new
instance . AKA Factory in Design pattern
.
.
.
From Khalid-Nowaf/animal/animal.go
Private vs Public Members
There is only one rule
Capital is Public ”exported”
Small is Private “unexported”
From Khalid-Nowaf/animal/animal.go
Classes In Action
To follow me make sure you Import my package by using this commands
go get github.com/khalid-nowaf/animal
go get github.com/khalid-nowaf/goExample
You will find the code in this path
{GOPATH}/src/Khalid-Nowaf/animal  Code implementation “package”
{GOPATH}/src/Khalid-Nowaf/goExample  Code Execution “main”
Inheritance and Composition
 Embedding akin to multiple inheritance
 embedded field named as “anonymous field”
 Let's call "base" the struct embedded
 And "derived" the struct doing the embedding.
 Base fields and methods are available as if they were declared in the
derived struct.
 But base fields and methods can be "shadowed"
 Shadowing: defining another field or method with the same name
(and signature) of a base field or method
Embedding and Shadowing
embedded.go “main”
output
embedded.go “Package”
Multiple Embedding
multiEmbedded.go “Package”
Multiple Embedding In Action
multiEmbedded.go (main)
More In Shadow Methods
Emedded.go “package”
Emedded.go “main”
Multiple inheritance and The Diamond Problem
 Golang solves the diamond problem by not allowing
diamonds.
 all embedded class-field-names should not collide
 You must rename fields if there is a name collision
 This rule avoids the diamond problem, by not allowing it
Interfaces
 The interface in Golang is designed to complement structs
 Struct: has fields and NON-VIRTUAL methods
 While, Interface has with NO fields, ALL VIRTUAL methods
 you can use an interface to:
 Declare a var or parameter of type interface.
 implement an interface, by declaring all the interface virtual
methods in a concrete class (a struct)
 Inherit (embed) a golang-interface into another golang-
interface
Interfaces = Polymorphism In Action
Since the code will not fit the slide ! , lets open
{GOPATH}/src/github.com/Khalid-Nowaf/animal/animal.go
To Sum-up …
 A golang struct-method
 It is defined outside of the class(struct) body
 extra section before the method name to define the "receiver" (this)
 Structs vs Interfaces
 Structs: **classes, with fields, ALL NON-VIRTUAL methods
 Interfaces: **classes, with NO fields, ALL VIRTUAL methods
 Interfaces used to impalement Polymorphism
 Shadowing: means defining another field or method with the same name (and
signature) of a base field or method
 GoLang can act as OOP if you wish , but its not by design

More Related Content

What's hot

Communication between Java and Python
Communication between Java and PythonCommunication between Java and Python
Communication between Java and Python
Andreas Schreiber
 
Go Language Hands-on Workshop Material
Go Language Hands-on Workshop MaterialGo Language Hands-on Workshop Material
Go Language Hands-on Workshop Material
Romin Irani
 
Introduction to go language programming
Introduction to go language programmingIntroduction to go language programming
Introduction to go language programming
Mahmoud Masih Tehrani
 
Groovy AST Demystified
Groovy AST DemystifiedGroovy AST Demystified
Groovy AST Demystified
Andres Almiray
 
What do you mean it needs to be Java based? How jython saved the day.
What do you mean it needs to be Java based? How jython saved the day.What do you mean it needs to be Java based? How jython saved the day.
What do you mean it needs to be Java based? How jython saved the day.
Mark Rees
 
Groovy AST Transformations
Groovy AST TransformationsGroovy AST Transformations
Groovy AST Transformations
hendersk
 
Apache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystemApache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystem
Kostas Saidis
 
Go lang introduction
Go lang introductionGo lang introduction
Go lang introduction
yangwm
 
welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?
sangam biradar
 
Java objects on steroids
Java objects on steroidsJava objects on steroids
Java objects on steroids
Romain Rochegude
 
Go. Why it goes
Go. Why it goesGo. Why it goes
Go. Why it goes
Sergey Pichkurov
 
Jython: Integrating Python and Java
Jython: Integrating Python and JavaJython: Integrating Python and Java
Jython: Integrating Python and Java
Charles Anderson
 
Dive into Pinkoi 2013
Dive into Pinkoi 2013Dive into Pinkoi 2013
Dive into Pinkoi 2013
Mosky Liu
 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microservice
Giulio De Donato
 
Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX Go
Rodolfo Carvalho
 
Mixing Python and Java
Mixing Python and JavaMixing Python and Java
Mixing Python and Java
Andreas Schreiber
 
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...Jerry Chou
 
Transmogrifier: content migration and time traveling
Transmogrifier: content migration and time travelingTransmogrifier: content migration and time traveling
Transmogrifier: content migration and time traveling
João Bueno
 
Debugging Python with gdb
Debugging Python with gdbDebugging Python with gdb
Debugging Python with gdb
Roman Podoliaka
 

What's hot (20)

Communication between Java and Python
Communication between Java and PythonCommunication between Java and Python
Communication between Java and Python
 
Go Language Hands-on Workshop Material
Go Language Hands-on Workshop MaterialGo Language Hands-on Workshop Material
Go Language Hands-on Workshop Material
 
Introduction to go language programming
Introduction to go language programmingIntroduction to go language programming
Introduction to go language programming
 
What's New in Groovy 1.6?
What's New in Groovy 1.6?What's New in Groovy 1.6?
What's New in Groovy 1.6?
 
Groovy AST Demystified
Groovy AST DemystifiedGroovy AST Demystified
Groovy AST Demystified
 
What do you mean it needs to be Java based? How jython saved the day.
What do you mean it needs to be Java based? How jython saved the day.What do you mean it needs to be Java based? How jython saved the day.
What do you mean it needs to be Java based? How jython saved the day.
 
Groovy AST Transformations
Groovy AST TransformationsGroovy AST Transformations
Groovy AST Transformations
 
Apache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystemApache Groovy: the language and the ecosystem
Apache Groovy: the language and the ecosystem
 
Go lang introduction
Go lang introductionGo lang introduction
Go lang introduction
 
welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?welcome to gopherlabs - why go (golang)?
welcome to gopherlabs - why go (golang)?
 
Java objects on steroids
Java objects on steroidsJava objects on steroids
Java objects on steroids
 
Go. Why it goes
Go. Why it goesGo. Why it goes
Go. Why it goes
 
Jython: Integrating Python and Java
Jython: Integrating Python and JavaJython: Integrating Python and Java
Jython: Integrating Python and Java
 
Dive into Pinkoi 2013
Dive into Pinkoi 2013Dive into Pinkoi 2013
Dive into Pinkoi 2013
 
Import golang; struct microservice
Import golang; struct microserviceImport golang; struct microservice
Import golang; struct microservice
 
Go 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX GoGo 1.10 Release Party - PDX Go
Go 1.10 Release Party - PDX Go
 
Mixing Python and Java
Mixing Python and JavaMixing Python and Java
Mixing Python and Java
 
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
 
Transmogrifier: content migration and time traveling
Transmogrifier: content migration and time travelingTransmogrifier: content migration and time traveling
Transmogrifier: content migration and time traveling
 
Debugging Python with gdb
Debugging Python with gdbDebugging Python with gdb
Debugging Python with gdb
 

Viewers also liked

Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
Bo-Yi Wu
 
Golang server design pattern
Golang server design patternGolang server design pattern
Golang server design pattern
理 傅
 
Functional go
Functional goFunctional go
Functional go
Geison Goes
 
13 practical tips for writing secure golang applications
13 practical tips for writing secure golang applications13 practical tips for writing secure golang applications
13 practical tips for writing secure golang applications
Karthik Gaekwad
 
A microservice architecture based on golang
A microservice architecture based on golangA microservice architecture based on golang
A microservice architecture based on golang
Gianfranco Reppucci
 
Golang 入門初體驗
Golang 入門初體驗Golang 入門初體驗
Golang 入門初體驗
政斌 楊
 
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
 [INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno [INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
Nexus FrontierTech
 
用 Docker 改善團隊合作模式
用 Docker 改善團隊合作模式用 Docker 改善團隊合作模式
用 Docker 改善團隊合作模式
Bo-Yi Wu
 
Boldly go where the Java programming language has never gone before
Boldly go where the Java programming language has never gone beforeBoldly go where the Java programming language has never gone before
Boldly go where the Java programming language has never gone beforeelliando dias
 
Beyond Java: Go for Java developers
Beyond Java: Go for Java developersBeyond Java: Go for Java developers
Beyond Java: Go for Java developers
Netcetera
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
Matt Stine
 
Symfony bundle fo asynchronous job processing
Symfony bundle fo asynchronous job processingSymfony bundle fo asynchronous job processing
Symfony bundle fo asynchronous job processing
Wojciech Ciołko
 
Asynchroniczny PHP i komunikacja czasu rzeczywistego z wykorzystaniem websocketw
Asynchroniczny PHP i komunikacja czasu rzeczywistego z wykorzystaniem websocketwAsynchroniczny PHP i komunikacja czasu rzeczywistego z wykorzystaniem websocketw
Asynchroniczny PHP i komunikacja czasu rzeczywistego z wykorzystaniem websocketw
Luke Adamczewski
 
Przetwarzanie asynchroniczne w zastosowaniach webowych
Przetwarzanie asynchroniczne w zastosowaniach webowychPrzetwarzanie asynchroniczne w zastosowaniach webowych
Przetwarzanie asynchroniczne w zastosowaniach webowych
leafnode
 
COSCUP 2016: Project 52 每週一個小專案來學習 Golang
COSCUP 2016: Project 52 每週一個小專案來學習 GolangCOSCUP 2016: Project 52 每週一個小專案來學習 Golang
COSCUP 2016: Project 52 每週一個小專案來學習 Golang
Evan Lin
 
CF WebUI - CloudFoundry User Group DACH
CF WebUI - CloudFoundry User Group DACHCF WebUI - CloudFoundry User Group DACH
CF WebUI - CloudFoundry User Group DACH
Lidia Fernández Garcés
 
Introduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceIntroduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript Conference
Bo-Yi Wu
 
Git Flow and JavaScript Coding Style
Git Flow and JavaScript Coding StyleGit Flow and JavaScript Coding Style
Git Flow and JavaScript Coding Style
Bo-Yi Wu
 
Golang Template
Golang TemplateGolang Template
Golang Template
Karthick Kumar
 
Gearman work queue in php
Gearman work queue in phpGearman work queue in php
Gearman work queue in php
Bo-Yi Wu
 

Viewers also liked (20)

Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
 
Golang server design pattern
Golang server design patternGolang server design pattern
Golang server design pattern
 
Functional go
Functional goFunctional go
Functional go
 
13 practical tips for writing secure golang applications
13 practical tips for writing secure golang applications13 practical tips for writing secure golang applications
13 practical tips for writing secure golang applications
 
A microservice architecture based on golang
A microservice architecture based on golangA microservice architecture based on golang
A microservice architecture based on golang
 
Golang 入門初體驗
Golang 入門初體驗Golang 入門初體驗
Golang 入門初體驗
 
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
 [INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno [INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
[INNOVATUBE] Tech Talk #3: Golang - Takaaki Mizuno
 
用 Docker 改善團隊合作模式
用 Docker 改善團隊合作模式用 Docker 改善團隊合作模式
用 Docker 改善團隊合作模式
 
Boldly go where the Java programming language has never gone before
Boldly go where the Java programming language has never gone beforeBoldly go where the Java programming language has never gone before
Boldly go where the Java programming language has never gone before
 
Beyond Java: Go for Java developers
Beyond Java: Go for Java developersBeyond Java: Go for Java developers
Beyond Java: Go for Java developers
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
 
Symfony bundle fo asynchronous job processing
Symfony bundle fo asynchronous job processingSymfony bundle fo asynchronous job processing
Symfony bundle fo asynchronous job processing
 
Asynchroniczny PHP i komunikacja czasu rzeczywistego z wykorzystaniem websocketw
Asynchroniczny PHP i komunikacja czasu rzeczywistego z wykorzystaniem websocketwAsynchroniczny PHP i komunikacja czasu rzeczywistego z wykorzystaniem websocketw
Asynchroniczny PHP i komunikacja czasu rzeczywistego z wykorzystaniem websocketw
 
Przetwarzanie asynchroniczne w zastosowaniach webowych
Przetwarzanie asynchroniczne w zastosowaniach webowychPrzetwarzanie asynchroniczne w zastosowaniach webowych
Przetwarzanie asynchroniczne w zastosowaniach webowych
 
COSCUP 2016: Project 52 每週一個小專案來學習 Golang
COSCUP 2016: Project 52 每週一個小專案來學習 GolangCOSCUP 2016: Project 52 每週一個小專案來學習 Golang
COSCUP 2016: Project 52 每週一個小專案來學習 Golang
 
CF WebUI - CloudFoundry User Group DACH
CF WebUI - CloudFoundry User Group DACHCF WebUI - CloudFoundry User Group DACH
CF WebUI - CloudFoundry User Group DACH
 
Introduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceIntroduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript Conference
 
Git Flow and JavaScript Coding Style
Git Flow and JavaScript Coding StyleGit Flow and JavaScript Coding Style
Git Flow and JavaScript Coding Style
 
Golang Template
Golang TemplateGolang Template
Golang Template
 
Gearman work queue in php
Gearman work queue in phpGearman work queue in php
Gearman work queue in php
 

Similar to Golang for OO Programmers

"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson
GWTcon
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010Rich Helton
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...Guillaume Laforge
 
Design patterns
Design patternsDesign patterns
Design patterns
Anas Alpure
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - Greach
HamletDRC
 
Greach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovyGreach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovy
Iván López Martín
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
Diego Freniche Brito
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Guillaume Laforge
 
Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016
Codemotion
 
Making Steaks from Sacred Cows
Making Steaks from Sacred CowsMaking Steaks from Sacred Cows
Making Steaks from Sacred Cows
Kevlin Henney
 
The GO Language : From Beginners to Gophers
The GO Language : From Beginners to GophersThe GO Language : From Beginners to Gophers
The GO Language : From Beginners to Gophers
Alessandro Sanino
 
Metaprogramming Rails
Metaprogramming RailsMetaprogramming Rails
Metaprogramming Rails
Justus Eapen
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
Andres Almiray
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyJames Williams
 
Java to Golang: An intro by Ryan Dawson Seldon.io
Java to Golang: An intro by Ryan Dawson Seldon.ioJava to Golang: An intro by Ryan Dawson Seldon.io
Java to Golang: An intro by Ryan Dawson Seldon.io
Mauricio (Salaboy) Salatino
 
Dependent things dependency management for apple sw - slideshare
Dependent things   dependency management for apple sw - slideshareDependent things   dependency management for apple sw - slideshare
Dependent things dependency management for apple sw - slideshare
Cavelle Benjamin
 
API workshop: Deep dive into Java
API workshop: Deep dive into JavaAPI workshop: Deep dive into Java
API workshop: Deep dive into Java
Tom Johnson
 
Gradle in a Polyglot World
Gradle in a Polyglot WorldGradle in a Polyglot World
Gradle in a Polyglot World
Schalk Cronjé
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming LanguageYLTO
 

Similar to Golang for OO Programmers (20)

"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson"Xapi-lang For declarative code generation" By James Nelson
"Xapi-lang For declarative code generation" By James Nelson
 
Intro Java Rev010
Intro Java Rev010Intro Java Rev010
Intro Java Rev010
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
 
Design patterns
Design patternsDesign patterns
Design patterns
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - Greach
 
Greach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovyGreach 2014 - Metaprogramming with groovy
Greach 2014 - Metaprogramming with groovy
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
 
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume LaforgeGroovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
Groovy and Grails in Action - Devoxx 2008 - University - Guillaume Laforge
 
Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016
 
Making Steaks from Sacred Cows
Making Steaks from Sacred CowsMaking Steaks from Sacred Cows
Making Steaks from Sacred Cows
 
The GO Language : From Beginners to Gophers
The GO Language : From Beginners to GophersThe GO Language : From Beginners to Gophers
The GO Language : From Beginners to Gophers
 
Metaprogramming Rails
Metaprogramming RailsMetaprogramming Rails
Metaprogramming Rails
 
Andy On Closures
Andy On ClosuresAndy On Closures
Andy On Closures
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
 
Java to Golang: An intro by Ryan Dawson Seldon.io
Java to Golang: An intro by Ryan Dawson Seldon.ioJava to Golang: An intro by Ryan Dawson Seldon.io
Java to Golang: An intro by Ryan Dawson Seldon.io
 
Dependent things dependency management for apple sw - slideshare
Dependent things   dependency management for apple sw - slideshareDependent things   dependency management for apple sw - slideshare
Dependent things dependency management for apple sw - slideshare
 
API workshop: Deep dive into Java
API workshop: Deep dive into JavaAPI workshop: Deep dive into Java
API workshop: Deep dive into Java
 
Gradle in a Polyglot World
Gradle in a Polyglot WorldGradle in a Polyglot World
Gradle in a Polyglot World
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming Language
 

Recently uploaded

Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 

Recently uploaded (20)

Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 

Golang for OO Programmers

  • 1. GoLang for OO Programmers Khalid Nowaf COSC 419 Special Topic : Golang and Docker Computer Science Okanagan College, 2016
  • 2. Before We Start  Import The presentation Packages by using this Commands  go get github.com/Khalid-Nowaf/goExample  go get github.com/Khalid-Nowaf/animal  go get github.com/Khalid-Nowaf/embedded  You should find all the code in this path  {GOPATH}/src/github.com/Khalid-Nowaf  The goExample package include the main files for our examples, where animal and embedded packages just the implementation  You should run any file in goExample by using this command  go run {filename}  E.g. go run class.go
  • 3. Agenda  Struct Types ”As Class”  Constructor and Custom Constructor “Factory”  Private and Public Struct Members  Embedded types (Composition)  Shadowing Fields and Methods  Interfaces
  • 4. Is GoLang OO ?  Classes  Encapsulation  Inheritance  Interfaces  Composition  delegation  Polymorphism “ Objects are like people. They’re living, breathing things that have knowledge inside them about how to do things and have memory inside them so they can remember things. And rather than interacting with them at a very low level, you interact with them at a very high level of abstraction, like we’re doing right here. “Steve Jobs
  • 6. Object In Go there is no such thing called Objects , but there is Types ! How to use ”this” keyword in Go ?
  • 7. Constructor Go has Built-in Constructor, but limited. From Khalid-Nowaf/animal/animal.go
  • 8. Custom Constructor To simulate the Constructor we create a method that return a new instance . AKA Factory in Design pattern . . . From Khalid-Nowaf/animal/animal.go
  • 9. Private vs Public Members There is only one rule Capital is Public ”exported” Small is Private “unexported” From Khalid-Nowaf/animal/animal.go
  • 10. Classes In Action To follow me make sure you Import my package by using this commands go get github.com/khalid-nowaf/animal go get github.com/khalid-nowaf/goExample You will find the code in this path {GOPATH}/src/Khalid-Nowaf/animal  Code implementation “package” {GOPATH}/src/Khalid-Nowaf/goExample  Code Execution “main”
  • 11. Inheritance and Composition  Embedding akin to multiple inheritance  embedded field named as “anonymous field”  Let's call "base" the struct embedded  And "derived" the struct doing the embedding.  Base fields and methods are available as if they were declared in the derived struct.  But base fields and methods can be "shadowed"  Shadowing: defining another field or method with the same name (and signature) of a base field or method
  • 12. Embedding and Shadowing embedded.go “main” output embedded.go “Package”
  • 14. Multiple Embedding In Action multiEmbedded.go (main)
  • 15. More In Shadow Methods Emedded.go “package” Emedded.go “main”
  • 16. Multiple inheritance and The Diamond Problem  Golang solves the diamond problem by not allowing diamonds.  all embedded class-field-names should not collide  You must rename fields if there is a name collision  This rule avoids the diamond problem, by not allowing it
  • 17. Interfaces  The interface in Golang is designed to complement structs  Struct: has fields and NON-VIRTUAL methods  While, Interface has with NO fields, ALL VIRTUAL methods  you can use an interface to:  Declare a var or parameter of type interface.  implement an interface, by declaring all the interface virtual methods in a concrete class (a struct)  Inherit (embed) a golang-interface into another golang- interface
  • 18. Interfaces = Polymorphism In Action Since the code will not fit the slide ! , lets open {GOPATH}/src/github.com/Khalid-Nowaf/animal/animal.go
  • 19. To Sum-up …  A golang struct-method  It is defined outside of the class(struct) body  extra section before the method name to define the "receiver" (this)  Structs vs Interfaces  Structs: **classes, with fields, ALL NON-VIRTUAL methods  Interfaces: **classes, with NO fields, ALL VIRTUAL methods  Interfaces used to impalement Polymorphism  Shadowing: means defining another field or method with the same name (and signature) of a base field or method  GoLang can act as OOP if you wish , but its not by design

Editor's Notes

  1. Abstraction: The process of picking out (abstracting) common features of objects and procedures. Class: A category of objects. The class defines all the common properties of the different objects that belong to it. Encapsulation: The process of combining elements to create a new entity. A procedure is a type of encapsulation because it combines a series of computer instructions. Information hiding: The process of hiding details of an object or function. Information hiding is a powerful programming technique because it reduces complexity. Inheritance: a feature that represents the "is a" relationship between different classes. Interface: the languages and codes that the applications use to communicate with each other and with the hardware. Messaging: Message passing is a form of communication used in parallel programming and object-oriented programming. Object: a self-contained entity that consists of both data and procedures to manipulate the data. Polymorphism: A programming language's ability to process objects differently depending on their data type or class. Procedure: a section of a program that performs a specific task.
  2. Embedding: a struct into another you have a mechanism similar to multiple inheritance with non-virtual members. Shadowing means defining another field or method with the same name (and signature) of a base field or method. Once shadowed, the only way to access the base member is to use the hidden field named as the base-struct-name.
  3. the only way to access the base member is to use the hidden field named as the base-struct-name. All base members can be accessed via the hidden field named as the base-struct-name. all inherited methods are called on the hidden-field-struct. It means that a base method cannot see or know about derived methods or fields. Everything is non-virtual. When working with structs and embedding, everything is STATICALLY LINKED. All references are resolved at compile time.
  4. Rmove e ..
  5. Since all golang-struct methods are non-virtual, you cannot override methods (you need interfaces for that) If you have a method show() for example in class/struct NamedObj and also define a method show() in class/struct Rectangle, Rectangle/show() will SHADOW the parent's class NamedObj/Show() As with base class fields, you can use the inherited class-name-as-field to access the base implementation via dot-notation var a derived = derived{base{"base-a", 10}, 20, 2.5} a.display() // calls Derived/display(a) // => "derived, a is: 2.5" a.base.display() // calls Base/display(a.base), the base implementation // => "base, a is: base-a" a.xyz() // "xyz" was not shadowed, calls Base/xyz(a.base) // => "xyz, a is: base-a"
  6. By restricting structs to non-virtual methods, and restricting interfaces to all-virtual methods and no fields. Both elements can be perfectly combined by embedding to create fast polymorphism and multiple inheritance without the problems associated to multiple inheritance in classical OOP