SlideShare a Scribd company logo
1 of 32
Design Patterns are not the rocket
science!
Kamil Mówiński
Agenda
• Design Patterns – still valuable?
• The world without spam – chain of responsibility
• Level designer - builder
• Watch out for walls – object pool
Design Patterns – still valuable?
definitely yes
The world without spam
• Have you ever consider how filtering in mailboxes works?
• What happens when you receive a new mail?
[
{
"title": "Test message",
"body": "Lorem ipsum",
"date": "2018-07-20 09:38:12",
"from": "example@example.com",
"to": "my_mail@example.com"
},
{
"title": "Test message with Spam title",
"body": "Lorem ipsum",
"date": "2018-07-20 09:18:12",
"from": "example@example.com",
"to": "my_mail@example.com"
},
{
"title": "Test message with weird body",
"body": "Lorem ipsum spam and another",
"date": "2018-07-20 09:38:12",
"from": "example@example.com",
"to": "my_mail@example.com"
}
]
Chain of responsibility
Problem
Solution
Chain of responsibility in scientific perspective
Filtering
• There is a “spam” word in a message title?
• There is a “spam” word in a message body?
• There is a message for me?
• There is a sender on a blacklist?
type Validator interface {
IsSpam(message.Message) bool
}
type Filter struct {
validator Validator
next *Filter
}
func NewFilter(filter Validator) *Filter {
return &Filter{validator: filter, next: nil}
}
Filtering in goroutines
func (f Filter) ValidateAllMessages(messages []message.Message) {
var wg sync.WaitGroup
for index := range messages {
wg.Add(1)
go f.validateMessage(&messages[index], &wg)
}
wg.Wait()
if f.isNextHandler() {
f.next.ValidateAllMessages(messages)
}
}
func (f Filter) isNextHandler() bool {
return f.next != nil
}
func (f Filter) validateMessage(msg *message.Message, wg *sync.WaitGroup) {
defer wg.Done()
if f.validator.IsSpam(*msg) {
msg.Spam = true
}
}
Title filtering
type TitleFilter struct {
Validator
}
func (TitleFilter) IsSpam(msg message.Message) bool {
return strings.Contains(strings.ToLower(msg.Title), "spam")
}
Recipient filter
type RecipientFilter struct {
Validator
}
func (RecipientFilter) IsSpam(msg message.Message) bool {
return strings.Compare(strings.ToLower(msg.To), "my_mail@example.com") != 0
}
Inbox
type Inbox struct {
Messages []message.Message
filters []*filters.Filter
}
func NewInbox(fileName string) (Inbox, error) {
var inbox Inbox
messages, err := message.ReadMessagesFromJson(fileName)
inbox.Messages = messages
return inbox, err
}
func (i *Inbox) AddFilter(filter *filters.Filter) {
if len(i.filters) != 0 {
i.filters[len(i.filters)-1].AddNextFilter(filter)
}
i.filters = append(i.filters, filter)
}
func (i Inbox) Filter() {
if len(i.filters) == 0 {
return
}
i.filters[0].ValidateAllMessages(i.Messages)
}
func (i Inbox) DisplayAllMessagesOnConsole() {
for _, message := range i.Messages {
message.DisplayOnConsole()
}
}
Structure
Constructor
Add filter (handler)
Filter (handle)
Display messages on console
Main function
func main() {
if len(os.Args) < 2 {
fmt.Printf("Necessary parameter <file_name> is missing")
return
}
messagesFile := os.Args[1]
incomingMessageBox, err := inbox.NewInbox(messagesFile)
if err != nil {
panic(err)
}
incomingMessageBox.AddFilter(filters.NewFilter(filters.TitleFilter{}))
incomingMessageBox.AddFilter(filters.NewFilter(filters.BodyFilter{}))
incomingMessageBox.AddFilter(filters.NewFilter(filters.RecipientFilter{}))
incomingMessageBox.AddFilter(filters.NewFilter(filters.SenderFilter{}))
incomingMessageBox.Filter()
incomingMessageBox.DisplayAllMessagesOnConsole()
}
Presentation time
https://github.com/Mowinski/go-design-patterns/tree/master/chain-of-responsibility
Map generator
• Let’s build a game level.
• A simple survive game needs generated maps (e.g. height maps).
• Blueprints of different kind of buildings:
• Heating building
• Smith building
• Shop building
• All buildings contains rooms
Example of level
Heating
Smith
Shop
Candy shop
Clever idea time
Builder in UML Charts
Class diagram
Sequence diagram
IBuilding
type IBuilding interface {
Build() (Building, error)
getOwner() player.Player
buildRooms() ([]Room, error)
}
type HeatingBuilding struct {
IBuilding
Owner player.Player
X int
Y int
}
type ShopBuilding struct {
IBuilding
Owner player.Player
X int
Y int
}
type SmithBuilding struct {
IBuilding
Owner player.Player
X int
Y int
}
func (_ ________) getOwner() player.Player {
return hb.Owner
}
type Room struct {
Map []Point
RoomLetter rune
}
Lets build a rooms
func (hb HeatingBuilding) buildRooms() ([]Room, error) {
mainRoom := Room{
Map: []Point{GetPoint(0, 0), GetPoint(10, 0), GetPoint(10, 10), GetPoint(0, 10)},
RoomLetter: 'm',
}
ovenRoom := Room{
Map: []Point{GetPoint(0, 10), GetPoint(10, 10), GetPoint(10, 15), GetPoint(0, 15)},
RoomLetter: 'o',
}
return []Room{mainRoom, ovenRoom}, nil
}
func (sb SmithBuilding) buildRooms() ([]Room, error) {
mainRoom := Room{
Map: []Point{GetPoint(0, 0), GetPoint(10, 0), GetPoint(10, 10), GetPoint(0, 10)},
RoomLetter: 'm',
}
smithRoom := Room{
Map: []Point{GetPoint(10, 0), GetPoint(20, 0), GetPoint(20, 5), GetPoint(10, 5)},
RoomLetter: 's',
}
anvilRoom := Room{
Map: []Point{GetPoint(0, 10), GetPoint(5, 10), GetPoint(5, 15), GetPoint(0, 15)},
RoomLetter: 'a',
}
return []Room{mainRoom, smithRoom, anvilRoom}, nil
}
Lets build a build!
func (sb ShopBuilding) Build() (Building, error) {
var building Building
var err error
building.Rooms, err = sb.buildRooms()
building.Endurance = 700.00
building.Owner = sb.getOwner()
building.X = sb.X
building.Y = sb.Y
return building, err
}
func (hb HeatingBuilding) Build() (Building, error) {
var building Building
var err error
building.Rooms, err = hb.buildRooms()
building.Endurance = 350.99
building.Owner = hb.getOwner()
building.X = hb.X
building.Y = hb.Y
return building, err
}
func (sb SmithBuilding) Build() (Building, error) {
var building Building
var err error
building.Rooms, err = sb.buildRooms()
building.Endurance = 900.00
building.Owner = sb.getOwner()
building.X = sb.X
building.Y = sb.Y
return building, err
}
Who is the boss?
type MapDirector struct {
Level level.Level
err error
}
func NewMapDirector(sizeX, sizeY int, player player.Player) (MapDirector, error) {
var mapDesigner MapDirector
heating := mapDesigner.buildWithErrorChecking(buildings.HeatingBuilding{Owner: player, X: 0, Y: 0})
smith := mapDesigner.buildWithErrorChecking(buildings.SmithBuilding{Owner: player , X: 15, Y: 15})
shop := mapDesigner.buildWithErrorChecking(buildings.ShopBuilding{Owner: player, X: 50, Y: 50})
candyShop := mapDesigner.buildWithErrorChecking(buildings.ShopBuilding{Owner: player, X: 0, Y: 50})
buildingsInMaps := []buildings.Building{*heating, *smith, *shop, *candyShop}
mapDesigner.Level = level.NewLevel(sizeX, sizeY, buildingsInMaps)
return mapDesigner, mapDesigner.err
}
func (md MapDirector) buildWithErrorChecking(builder buildings.IBuilding) *buildings.Building {
var building buildings.Building
if md.err != nil {
return nil
}
building, md.err = builder.Build()
return &building
}
func main() {
}
playerOne := player.NewPlayer("TestPlayer")
mapDirector, err := director.NewMapDirector(100, 100, playerOne)
if err != nil {
fmt.Printf("Error occure: %v", err)
os.Exit(1)
}
mapCharacters := mapDirector.Level.Render()
mapCharacters.ShowInConsole()
err = mapCharacters.SaveToFile("map.jpeg", mapDirector.Level.SizeX, mapDirector.Level.SizeY)
if err != nil {
fmt.Printf("Error occure: %v", err)
os.Exit(2)
}
Presentation time
https://github.com/Mowinski/go-design-patterns/tree/master/builder
Frogger style game
Frogger style game
Level
type Level struct {
Board [][]rune
XSize, YSize uint
wallPool *object_pool.WallPool
actors []interfaces.Actor
nextWallWidth uint
}
func NewLevel(XSize, YSize uint, wallPool *object_pool.WallPool) Level {
board := make([][]rune, XSize)
for i := range board {
board[i] = make([]rune, YSize)
}
level := Level{Board: board, XSize: XSize, YSize: YSize, wallPool: wallPool}
level.clear()
return level
}
func (l *Level) clear() {
for x := range l.Board {
for y := range l.Board[x] {
l.Board[x][y] = ' '
}
}
}
func (l *Level) printRenderedBoardOnConsole() {
for x := range l.Board {
for y := range l.Board[x] {
fmt.Printf("%c", l.Board[x][y])
}
fmt.Printf("n")
}
}
func (l *Level) RenderOnConsole() {
l.clear()
l.addWall()
l.renderActors()
l.printWallStatsSummary()
l.printRenderedBoardOnConsole()
}
Player and actors
type Actor interface {
Render(ILevel)
}
type Player struct {
interfaces.Actor
X, Y uint
currentLevel interfaces.ILevel
}
type Wall struct {
interfaces.Actor
X, Y uint
Width uint
}
Walls
func NewWall(x, y, width uint) Wall {
return Wall{X: x, Y: y, Width: width}
}
func GenerateRandomWidthWall(xLevelSize, yLevelSize uint) Wall {
time.Sleep(time.Second * 2)
randomX := uint(rand.Int31n(int32(xLevelSize - MAXSIZE)))
randomY := uint(rand.Int31n(int32(yLevelSize)))
randomWidth := uint(rand.Int31n(MAXSIZE + 1))
return NewWall(randomX, randomY, randomWidth)
}
func (w Wall) Render(level interfaces.ILevel) {
for i := uint(0); i < w.Width; i++ {
level.SetObjectOnBoard(w.X + i, w.Y, '-')
}
}
How to implement it?
Wall-pool structure
type WallPool struct {
walls map[uint][]actors.Wall
generatingWall bool
}
func (wp WallPool) GetInstanceWithWidth(width uint) actors.Wall {
wall := wp.walls[width][0]
wp.walls[width] = wp.walls[width][1:]
return wall
}
func (wp *WallPool) StopGeneratingWalls() {
wp.generatingWall = false
}
func (l *Level) addWall() {
l.nextWallWidth = (l.nextWallWidth + 1) % (actors.MAXSIZE + 1)
wall := l.wallPool.GetInstanceWithWidth(l.nextWallWidth)
l.AddActorToRenderList(&wall)
}
Presentation time
https://github.com/Mowinski/go-design-patterns/tree/master/object-pool
The End

More Related Content

What's hot

The Ring programming language version 1.8 book - Part 46 of 202
The Ring programming language version 1.8 book - Part 46 of 202The Ring programming language version 1.8 book - Part 46 of 202
The Ring programming language version 1.8 book - Part 46 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212Mahmoud Samir Fayed
 
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Suyeol Jeon
 
The Ring programming language version 1.2 book - Part 19 of 84
The Ring programming language version 1.2 book - Part 19 of 84The Ring programming language version 1.2 book - Part 19 of 84
The Ring programming language version 1.2 book - Part 19 of 84Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 37 of 181
The Ring programming language version 1.5.2 book - Part 37 of 181The Ring programming language version 1.5.2 book - Part 37 of 181
The Ring programming language version 1.5.2 book - Part 37 of 181Mahmoud Samir Fayed
 
RxSwift 시작하기
RxSwift 시작하기RxSwift 시작하기
RxSwift 시작하기Suyeol Jeon
 
Fabric.js @ Falsy Values
Fabric.js @ Falsy ValuesFabric.js @ Falsy Values
Fabric.js @ Falsy ValuesJuriy Zaytsev
 
The Ring programming language version 1.7 book - Part 41 of 196
The Ring programming language version 1.7 book - Part 41 of 196The Ring programming language version 1.7 book - Part 41 of 196
The Ring programming language version 1.7 book - Part 41 of 196Mahmoud Samir Fayed
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programsKaruppaiyaa123
 
Ruby Language - A quick tour
Ruby Language - A quick tourRuby Language - A quick tour
Ruby Language - A quick touraztack
 
mobl - model-driven engineering lecture
mobl - model-driven engineering lecturemobl - model-driven engineering lecture
mobl - model-driven engineering lecturezefhemel
 
The Ring programming language version 1.9 book - Part 46 of 210
The Ring programming language version 1.9 book - Part 46 of 210The Ring programming language version 1.9 book - Part 46 of 210
The Ring programming language version 1.9 book - Part 46 of 210Mahmoud Samir Fayed
 
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Tomasz Dziuda
 
The Ring programming language version 1.10 book - Part 52 of 212
The Ring programming language version 1.10 book - Part 52 of 212The Ring programming language version 1.10 book - Part 52 of 212
The Ring programming language version 1.10 book - Part 52 of 212Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 42 of 184
The Ring programming language version 1.5.3 book - Part 42 of 184The Ring programming language version 1.5.3 book - Part 42 of 184
The Ring programming language version 1.5.3 book - Part 42 of 184Mahmoud Samir Fayed
 
Lecture on Rubinius for Compiler Construction at University of Twente
Lecture on Rubinius for Compiler Construction at University of TwenteLecture on Rubinius for Compiler Construction at University of Twente
Lecture on Rubinius for Compiler Construction at University of TwenteDirkjan Bussink
 
From Java to Kotlin beyond alt+shift+cmd+k - Kotlin Community Conf Milan
From Java to Kotlin beyond alt+shift+cmd+k - Kotlin Community Conf MilanFrom Java to Kotlin beyond alt+shift+cmd+k - Kotlin Community Conf Milan
From Java to Kotlin beyond alt+shift+cmd+k - Kotlin Community Conf MilanFabio Collini
 
Sistema de ventas
Sistema de ventasSistema de ventas
Sistema de ventasDAYANA RETO
 

What's hot (20)

The Ring programming language version 1.8 book - Part 46 of 202
The Ring programming language version 1.8 book - Part 46 of 202The Ring programming language version 1.8 book - Part 46 of 202
The Ring programming language version 1.8 book - Part 46 of 202
 
The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.10 book - Part 31 of 212
 
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
 
The Ring programming language version 1.2 book - Part 19 of 84
The Ring programming language version 1.2 book - Part 19 of 84The Ring programming language version 1.2 book - Part 19 of 84
The Ring programming language version 1.2 book - Part 19 of 84
 
The Ring programming language version 1.5.2 book - Part 37 of 181
The Ring programming language version 1.5.2 book - Part 37 of 181The Ring programming language version 1.5.2 book - Part 37 of 181
The Ring programming language version 1.5.2 book - Part 37 of 181
 
RxSwift 시작하기
RxSwift 시작하기RxSwift 시작하기
RxSwift 시작하기
 
Fabric.js @ Falsy Values
Fabric.js @ Falsy ValuesFabric.js @ Falsy Values
Fabric.js @ Falsy Values
 
The Ring programming language version 1.7 book - Part 41 of 196
The Ring programming language version 1.7 book - Part 41 of 196The Ring programming language version 1.7 book - Part 41 of 196
The Ring programming language version 1.7 book - Part 41 of 196
 
java experiments and programs
java experiments and programsjava experiments and programs
java experiments and programs
 
Ruby Language - A quick tour
Ruby Language - A quick tourRuby Language - A quick tour
Ruby Language - A quick tour
 
mobl - model-driven engineering lecture
mobl - model-driven engineering lecturemobl - model-driven engineering lecture
mobl - model-driven engineering lecture
 
The Ring programming language version 1.9 book - Part 46 of 210
The Ring programming language version 1.9 book - Part 46 of 210The Ring programming language version 1.9 book - Part 46 of 210
The Ring programming language version 1.9 book - Part 46 of 210
 
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Introduction to ECMAScript 2015
Introduction to ECMAScript 2015
 
Python speleology
Python speleologyPython speleology
Python speleology
 
The Ring programming language version 1.10 book - Part 52 of 212
The Ring programming language version 1.10 book - Part 52 of 212The Ring programming language version 1.10 book - Part 52 of 212
The Ring programming language version 1.10 book - Part 52 of 212
 
The Ring programming language version 1.5.3 book - Part 42 of 184
The Ring programming language version 1.5.3 book - Part 42 of 184The Ring programming language version 1.5.3 book - Part 42 of 184
The Ring programming language version 1.5.3 book - Part 42 of 184
 
Prototype UI Intro
Prototype UI IntroPrototype UI Intro
Prototype UI Intro
 
Lecture on Rubinius for Compiler Construction at University of Twente
Lecture on Rubinius for Compiler Construction at University of TwenteLecture on Rubinius for Compiler Construction at University of Twente
Lecture on Rubinius for Compiler Construction at University of Twente
 
From Java to Kotlin beyond alt+shift+cmd+k - Kotlin Community Conf Milan
From Java to Kotlin beyond alt+shift+cmd+k - Kotlin Community Conf MilanFrom Java to Kotlin beyond alt+shift+cmd+k - Kotlin Community Conf Milan
From Java to Kotlin beyond alt+shift+cmd+k - Kotlin Community Conf Milan
 
Sistema de ventas
Sistema de ventasSistema de ventas
Sistema de ventas
 

Similar to Design Patterns in Go Code

JavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your codeJavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your codeLaurence Svekis ✔
 
FITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an endFITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an endThibault Imbert
 
Technology: A Means to an End with Thibault Imbert
Technology: A Means to an End with Thibault ImbertTechnology: A Means to an End with Thibault Imbert
Technology: A Means to an End with Thibault ImbertFITC
 
JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervosoLuis Vendrame
 
The Ring programming language version 1.5.4 book - Part 40 of 185
The Ring programming language version 1.5.4 book - Part 40 of 185The Ring programming language version 1.5.4 book - Part 40 of 185
The Ring programming language version 1.5.4 book - Part 40 of 185Mahmoud Samir Fayed
 
do ruby ao golang: o que aprendi criando um microserviço depois de 5000 commits
do ruby ao golang: o que aprendi criando um microserviço depois de 5000 commitsdo ruby ao golang: o que aprendi criando um microserviço depois de 5000 commits
do ruby ao golang: o que aprendi criando um microserviço depois de 5000 commitsAndreLeoni1
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
The Ring programming language version 1.5.3 book - Part 40 of 184
The Ring programming language version 1.5.3 book - Part 40 of 184The Ring programming language version 1.5.3 book - Part 40 of 184
The Ring programming language version 1.5.3 book - Part 40 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 50 of 212
The Ring programming language version 1.10 book - Part 50 of 212The Ring programming language version 1.10 book - Part 50 of 212
The Ring programming language version 1.10 book - Part 50 of 212Mahmoud Samir Fayed
 
Stamps - a better way to object composition
Stamps - a better way to object compositionStamps - a better way to object composition
Stamps - a better way to object compositionVasyl Boroviak
 
js+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdfjs+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdfNuttavutThongjor1
 
fullstack typescript with react and express.pdf
fullstack typescript with react and express.pdffullstack typescript with react and express.pdf
fullstack typescript with react and express.pdfNuttavutThongjor1
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs偉格 高
 
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDBNate Abele
 
The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196Mahmoud Samir Fayed
 

Similar to Design Patterns in Go Code (20)

JavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your codeJavaScript Advanced - Useful methods to power up your code
JavaScript Advanced - Useful methods to power up your code
 
FITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an endFITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an end
 
Technology: A Means to an End with Thibault Imbert
Technology: A Means to an End with Thibault ImbertTechnology: A Means to an End with Thibault Imbert
Technology: A Means to an End with Thibault Imbert
 
MongoDB
MongoDBMongoDB
MongoDB
 
JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervoso
 
The Ring programming language version 1.5.4 book - Part 40 of 185
The Ring programming language version 1.5.4 book - Part 40 of 185The Ring programming language version 1.5.4 book - Part 40 of 185
The Ring programming language version 1.5.4 book - Part 40 of 185
 
do ruby ao golang: o que aprendi criando um microserviço depois de 5000 commits
do ruby ao golang: o que aprendi criando um microserviço depois de 5000 commitsdo ruby ao golang: o que aprendi criando um microserviço depois de 5000 commits
do ruby ao golang: o que aprendi criando um microserviço depois de 5000 commits
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
The Ring programming language version 1.5.3 book - Part 40 of 184
The Ring programming language version 1.5.3 book - Part 40 of 184The Ring programming language version 1.5.3 book - Part 40 of 184
The Ring programming language version 1.5.3 book - Part 40 of 184
 
The Ring programming language version 1.10 book - Part 50 of 212
The Ring programming language version 1.10 book - Part 50 of 212The Ring programming language version 1.10 book - Part 50 of 212
The Ring programming language version 1.10 book - Part 50 of 212
 
Stamps - a better way to object composition
Stamps - a better way to object compositionStamps - a better way to object composition
Stamps - a better way to object composition
 
ts+js
ts+jsts+js
ts+js
 
js+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdfjs+ts fullstack typescript with react and express.pdf
js+ts fullstack typescript with react and express.pdf
 
fullstack typescript with react and express.pdf
fullstack typescript with react and express.pdffullstack typescript with react and express.pdf
fullstack typescript with react and express.pdf
 
mobl
moblmobl
mobl
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDB
 
The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196
 
ES6, WTF?
ES6, WTF?ES6, WTF?
ES6, WTF?
 

Recently uploaded

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...Call Girls in Nagpur High Profile
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 

Recently uploaded (20)

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 

Design Patterns in Go Code

  • 1. Design Patterns are not the rocket science! Kamil Mówiński
  • 2. Agenda • Design Patterns – still valuable? • The world without spam – chain of responsibility • Level designer - builder • Watch out for walls – object pool
  • 3. Design Patterns – still valuable? definitely yes
  • 4. The world without spam • Have you ever consider how filtering in mailboxes works? • What happens when you receive a new mail? [ { "title": "Test message", "body": "Lorem ipsum", "date": "2018-07-20 09:38:12", "from": "example@example.com", "to": "my_mail@example.com" }, { "title": "Test message with Spam title", "body": "Lorem ipsum", "date": "2018-07-20 09:18:12", "from": "example@example.com", "to": "my_mail@example.com" }, { "title": "Test message with weird body", "body": "Lorem ipsum spam and another", "date": "2018-07-20 09:38:12", "from": "example@example.com", "to": "my_mail@example.com" } ]
  • 6. Chain of responsibility in scientific perspective
  • 7. Filtering • There is a “spam” word in a message title? • There is a “spam” word in a message body? • There is a message for me? • There is a sender on a blacklist? type Validator interface { IsSpam(message.Message) bool } type Filter struct { validator Validator next *Filter } func NewFilter(filter Validator) *Filter { return &Filter{validator: filter, next: nil} }
  • 8. Filtering in goroutines func (f Filter) ValidateAllMessages(messages []message.Message) { var wg sync.WaitGroup for index := range messages { wg.Add(1) go f.validateMessage(&messages[index], &wg) } wg.Wait() if f.isNextHandler() { f.next.ValidateAllMessages(messages) } } func (f Filter) isNextHandler() bool { return f.next != nil } func (f Filter) validateMessage(msg *message.Message, wg *sync.WaitGroup) { defer wg.Done() if f.validator.IsSpam(*msg) { msg.Spam = true } }
  • 9. Title filtering type TitleFilter struct { Validator } func (TitleFilter) IsSpam(msg message.Message) bool { return strings.Contains(strings.ToLower(msg.Title), "spam") }
  • 10. Recipient filter type RecipientFilter struct { Validator } func (RecipientFilter) IsSpam(msg message.Message) bool { return strings.Compare(strings.ToLower(msg.To), "my_mail@example.com") != 0 }
  • 11. Inbox type Inbox struct { Messages []message.Message filters []*filters.Filter } func NewInbox(fileName string) (Inbox, error) { var inbox Inbox messages, err := message.ReadMessagesFromJson(fileName) inbox.Messages = messages return inbox, err } func (i *Inbox) AddFilter(filter *filters.Filter) { if len(i.filters) != 0 { i.filters[len(i.filters)-1].AddNextFilter(filter) } i.filters = append(i.filters, filter) } func (i Inbox) Filter() { if len(i.filters) == 0 { return } i.filters[0].ValidateAllMessages(i.Messages) } func (i Inbox) DisplayAllMessagesOnConsole() { for _, message := range i.Messages { message.DisplayOnConsole() } } Structure Constructor Add filter (handler) Filter (handle) Display messages on console
  • 12. Main function func main() { if len(os.Args) < 2 { fmt.Printf("Necessary parameter <file_name> is missing") return } messagesFile := os.Args[1] incomingMessageBox, err := inbox.NewInbox(messagesFile) if err != nil { panic(err) } incomingMessageBox.AddFilter(filters.NewFilter(filters.TitleFilter{})) incomingMessageBox.AddFilter(filters.NewFilter(filters.BodyFilter{})) incomingMessageBox.AddFilter(filters.NewFilter(filters.RecipientFilter{})) incomingMessageBox.AddFilter(filters.NewFilter(filters.SenderFilter{})) incomingMessageBox.Filter() incomingMessageBox.DisplayAllMessagesOnConsole() }
  • 14. Map generator • Let’s build a game level. • A simple survive game needs generated maps (e.g. height maps). • Blueprints of different kind of buildings: • Heating building • Smith building • Shop building • All buildings contains rooms
  • 17. Builder in UML Charts Class diagram Sequence diagram
  • 18. IBuilding type IBuilding interface { Build() (Building, error) getOwner() player.Player buildRooms() ([]Room, error) } type HeatingBuilding struct { IBuilding Owner player.Player X int Y int } type ShopBuilding struct { IBuilding Owner player.Player X int Y int } type SmithBuilding struct { IBuilding Owner player.Player X int Y int } func (_ ________) getOwner() player.Player { return hb.Owner } type Room struct { Map []Point RoomLetter rune }
  • 19. Lets build a rooms func (hb HeatingBuilding) buildRooms() ([]Room, error) { mainRoom := Room{ Map: []Point{GetPoint(0, 0), GetPoint(10, 0), GetPoint(10, 10), GetPoint(0, 10)}, RoomLetter: 'm', } ovenRoom := Room{ Map: []Point{GetPoint(0, 10), GetPoint(10, 10), GetPoint(10, 15), GetPoint(0, 15)}, RoomLetter: 'o', } return []Room{mainRoom, ovenRoom}, nil } func (sb SmithBuilding) buildRooms() ([]Room, error) { mainRoom := Room{ Map: []Point{GetPoint(0, 0), GetPoint(10, 0), GetPoint(10, 10), GetPoint(0, 10)}, RoomLetter: 'm', } smithRoom := Room{ Map: []Point{GetPoint(10, 0), GetPoint(20, 0), GetPoint(20, 5), GetPoint(10, 5)}, RoomLetter: 's', } anvilRoom := Room{ Map: []Point{GetPoint(0, 10), GetPoint(5, 10), GetPoint(5, 15), GetPoint(0, 15)}, RoomLetter: 'a', } return []Room{mainRoom, smithRoom, anvilRoom}, nil }
  • 20. Lets build a build! func (sb ShopBuilding) Build() (Building, error) { var building Building var err error building.Rooms, err = sb.buildRooms() building.Endurance = 700.00 building.Owner = sb.getOwner() building.X = sb.X building.Y = sb.Y return building, err } func (hb HeatingBuilding) Build() (Building, error) { var building Building var err error building.Rooms, err = hb.buildRooms() building.Endurance = 350.99 building.Owner = hb.getOwner() building.X = hb.X building.Y = hb.Y return building, err } func (sb SmithBuilding) Build() (Building, error) { var building Building var err error building.Rooms, err = sb.buildRooms() building.Endurance = 900.00 building.Owner = sb.getOwner() building.X = sb.X building.Y = sb.Y return building, err }
  • 21. Who is the boss? type MapDirector struct { Level level.Level err error } func NewMapDirector(sizeX, sizeY int, player player.Player) (MapDirector, error) { var mapDesigner MapDirector heating := mapDesigner.buildWithErrorChecking(buildings.HeatingBuilding{Owner: player, X: 0, Y: 0}) smith := mapDesigner.buildWithErrorChecking(buildings.SmithBuilding{Owner: player , X: 15, Y: 15}) shop := mapDesigner.buildWithErrorChecking(buildings.ShopBuilding{Owner: player, X: 50, Y: 50}) candyShop := mapDesigner.buildWithErrorChecking(buildings.ShopBuilding{Owner: player, X: 0, Y: 50}) buildingsInMaps := []buildings.Building{*heating, *smith, *shop, *candyShop} mapDesigner.Level = level.NewLevel(sizeX, sizeY, buildingsInMaps) return mapDesigner, mapDesigner.err } func (md MapDirector) buildWithErrorChecking(builder buildings.IBuilding) *buildings.Building { var building buildings.Building if md.err != nil { return nil } building, md.err = builder.Build() return &building }
  • 22. func main() { } playerOne := player.NewPlayer("TestPlayer") mapDirector, err := director.NewMapDirector(100, 100, playerOne) if err != nil { fmt.Printf("Error occure: %v", err) os.Exit(1) } mapCharacters := mapDirector.Level.Render() mapCharacters.ShowInConsole() err = mapCharacters.SaveToFile("map.jpeg", mapDirector.Level.SizeX, mapDirector.Level.SizeY) if err != nil { fmt.Printf("Error occure: %v", err) os.Exit(2) }
  • 26. Level type Level struct { Board [][]rune XSize, YSize uint wallPool *object_pool.WallPool actors []interfaces.Actor nextWallWidth uint } func NewLevel(XSize, YSize uint, wallPool *object_pool.WallPool) Level { board := make([][]rune, XSize) for i := range board { board[i] = make([]rune, YSize) } level := Level{Board: board, XSize: XSize, YSize: YSize, wallPool: wallPool} level.clear() return level } func (l *Level) clear() { for x := range l.Board { for y := range l.Board[x] { l.Board[x][y] = ' ' } } } func (l *Level) printRenderedBoardOnConsole() { for x := range l.Board { for y := range l.Board[x] { fmt.Printf("%c", l.Board[x][y]) } fmt.Printf("n") } } func (l *Level) RenderOnConsole() { l.clear() l.addWall() l.renderActors() l.printWallStatsSummary() l.printRenderedBoardOnConsole() }
  • 27. Player and actors type Actor interface { Render(ILevel) } type Player struct { interfaces.Actor X, Y uint currentLevel interfaces.ILevel } type Wall struct { interfaces.Actor X, Y uint Width uint }
  • 28. Walls func NewWall(x, y, width uint) Wall { return Wall{X: x, Y: y, Width: width} } func GenerateRandomWidthWall(xLevelSize, yLevelSize uint) Wall { time.Sleep(time.Second * 2) randomX := uint(rand.Int31n(int32(xLevelSize - MAXSIZE))) randomY := uint(rand.Int31n(int32(yLevelSize))) randomWidth := uint(rand.Int31n(MAXSIZE + 1)) return NewWall(randomX, randomY, randomWidth) } func (w Wall) Render(level interfaces.ILevel) { for i := uint(0); i < w.Width; i++ { level.SetObjectOnBoard(w.X + i, w.Y, '-') } }
  • 30. Wall-pool structure type WallPool struct { walls map[uint][]actors.Wall generatingWall bool } func (wp WallPool) GetInstanceWithWidth(width uint) actors.Wall { wall := wp.walls[width][0] wp.walls[width] = wp.walls[width][1:] return wall } func (wp *WallPool) StopGeneratingWalls() { wp.generatingWall = false } func (l *Level) addWall() { l.nextWallWidth = (l.nextWallWidth + 1) % (actors.MAXSIZE + 1) wall := l.wallPool.GetInstanceWithWidth(l.nextWallWidth) l.AddActorToRenderList(&wall) }

Editor's Notes

  1. Czy design patterny dalej żyją czy sa to już dinozaury? Zaprezentuje i polecę apki do napisania dla 3 design patternów
  2. C++, Java bez sprzecznie wzorce sa uzyteczne W Pythonie i GoLang – do rozwagi
  3. Minuta na zastanowienie się jak filtrują wiadomości w klientach mailowych Struktura przechowująca maile
  4. Mamy do odpalenia kilka elementow ktore przetwarzaja obiekt Zrobmy z nich liste
  5. Struktura wzorca. Client przechowuje liste przetwarzajacych Client pozwala dodawac nowych przetwarzajacych (dbajac o zaleznosc listy) Przetwarzajacy obiekt Przetwarza Dodaje nastepny element do siebie Workflow Tworzymy 3 handlery Dodajemy je do listy Wrzucamy obj do przetwarzania dla clienta
  6. Filtr tytulu maila Filtr tresci maila Filtr czy napewno do mnie (moze sprawdzac imie I nazwisko np.) Filtr czy uzytkownik nie jest na czarnej liscie Interfejs filtrow: Handle -> sprawdza wiadomosc AddNext -> dodaje kolejny filtr
  7. 1. Pamietaj o breakpointach w filtrach
  8. 2. Tytuly takie jak Rust, Minecraft, Ark, Don’t Starve
  9. Kolory to pokoje Heating: Czarny glowny pokoj Rozowy pokoj grzewczy Smith: Czarny glowny pokoj Niebieski Pokoj kowala Zolty kowadlo I reszta sprzetu Shop Czarny glowny pokoj Zolty magazyn Brazowy toaleta Niebieski pokoj kierwonictwa
  10. Po co err? Przekonamy sie przy budowie Konstuktor, moze randomowo tworzyc mapy albo miec zafixowane. Wykorzystujemy mechanism uproszczajacy obsluge bledow (md.err)
  11. 1. Frogger
  12. 1. Panic gdy nie ma zasobow