Golang, OOP,

and Design Patterns

outline

  • Introduction
  • The problem in Golang
  • Examples in Strategy
    and Observer patterns
  • Inheritance in Golang

Introduction

golang

Data are encapsulated in packages, which means, objects in the same package can freely alter and access others

Object-oriented programming

Objects are the collection of states which can be altered and accessed by, and only by, methods

the Problem in golang

from OOP's perpective

Accessing an object's data is not safe

Examples in strategy pattern

Examples in observer pattern

Inheritance in golang

There is no inheritance in Golang!

ATTEMPT to implement
template method pattern

Q/A

Golang, OOP, and Design Patterns

By whcwhc78

Golang, OOP, and Design Patterns

  • 387