Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Design pattern is: ● Solution. ● Template. ● Best practice. ● Obect-oriented. ● Language extension. ● Means of communication.

Slide 3

Slide 3 text

Creational patterns: Factory method Lazy initialization Singleton Structural patterns: Adapter Decorator Behavioral patterns: Value object Null Object Strategy Command Chain of responsibility Dependency injection

Slide 4

Slide 4 text

Factory method «Salty Oat Cookies» by Kimberly Vardeman from http://www.flickr.com/photos/kimberlykv/5061421858/, available under a Creative Commons Attribution 2.0 Generic license: http://creativecommons.org/licenses/by/2.0/

Slide 5

Slide 5 text

Factory method ● Provides an interface for creating an object. ● Encapsulates class instantiation in a method. ● Lets subclasses decide which class to instantiate. Allows to: ● extract complex object creation code, ● select which class to instantiate, ● cache objects.

Slide 6

Slide 6 text

Factory method

Slide 7

Slide 7 text

Factory method

Slide 8

Slide 8 text

Lazy initialization Photo by Viola Heusser from http://pixabay.com/en/hangover-cat-domestic-cat-black-173669/, available under a Creative Commons CC0 1.0 Universal license: http://creativecommons.org/publicdomain/zero/1.0/

Slide 9

Slide 9 text

Lazy initialization ● A special case of lazy evaluation strategy. ● Initializes a value/object on its first access. Allows to: ● defer expensive computation.

Slide 10

Slide 10 text

Lazy initialization

Slide 11

Slide 11 text

Lazy initialization

Slide 12

Slide 12 text

Singleton «The Solitary Tree» by Bobbi Jones Jones from http://www.publicdomainpictures.net/view-image.php?image=22282, available under a Creative Commons CC0 1.0 Universal license: http://creativecommons.org/publicdomain/zero/1.0/

Slide 13

Slide 13 text

Singleton ● Restricts the instantiation to one object. ● Provides a global point of access to it. Allows to: ● limit number of class objects, ● implement interfaces, ● use lazy initialization.

Slide 14

Slide 14 text

Singleton

Slide 15

Slide 15 text

Singleton

Slide 16

Slide 16 text

Adapter «Multiple jacks / adaptors» by Mihai Andoni from http://www.sxc.hu/photo/972429

Slide 17

Slide 17 text

Adapter ● Converts an interface into expected interface. Allows to: ● integrate incompatible classes, ● adapt existing components.

Slide 18

Slide 18 text

Adapter

Slide 19

Slide 19 text

Adapter

Slide 20

Slide 20 text

Decorator «Colour Pencils» by George Hodan from http://www.publicdomainpictures.net/view-image.php?image=25646, available under a Creative Commons CC0 1.0 Universal license: http://creativecommons.org/publicdomain/zero/1.0/

Slide 21

Slide 21 text

Decorator ● Extends functionality of a particular object. ● Provides a flexible alternative to subclassing. Allows to: ● decorate final classes, ● arbitrarily combine extensions.

Slide 22

Slide 22 text

Decorator

Slide 23

Slide 23 text

Decorator

Slide 24

Slide 24 text

Value object «Dollars» by Виталий Смолыгин from http://publicdomainpictures.net/view-image.php?image=31593, available under a Creative Commons CC0 1.0 Universal license: http://creativecommons.org/publicdomain/zero/1.0/

Slide 25

Slide 25 text

Value object ● A small immutable object. ● Equality isn’t based on identity. Allows to: ● represent numbers, dates, colors, etc, ● implement inter-process communication, ● simplify multi-threaded programing.

Slide 26

Slide 26 text

Value object

Slide 27

Slide 27 text

Value object Tuple: Tuple with a type alias: Case class:

Slide 28

Slide 28 text

Null Object «Mr. Invisible at the beach» by Carlos Koblischek from http://www.sxc.hu/photo/348295

Slide 29

Slide 29 text

Null Object ● Represents the absence of an object. ● Implements «do-nothing» behavior. Allows to: ● avoid explicit checks of reference validity.

Slide 30

Slide 30 text

Null Object

Slide 31

Slide 31 text

Null Object

Slide 32

Slide 32 text

Strategy Photo by Nachrichten_muc from http://pixabay.com/en/chess-chess-board-black-play-white-140340/, available under Creative Commons CC0 1.0 Universal license http://creativecommons.org/publicdomain/zero/1.0/

Slide 33

Slide 33 text

Strategy ● Defines a family of encapsulated algorithms. ● Vary algorithms independently from clients. Allows to: ● select an algorithm at runtime.

Slide 34

Slide 34 text

Strategy

Slide 35

Slide 35 text

Strategy

Slide 36

Slide 36 text

Command «Dog Stick Water» by Randen Pederson from http://www.flickr.com/photos/chefranden/2668370301, available under a Creative Commons Attribution 2.0 Generic license: http://creativecommons.org/licenses/by/2.0/

Slide 37

Slide 37 text

Command ● Encapsulates information about a mehtod call. ● Provides a way to call the method later. Allows to: ● delay, sequence or log method calls.

Slide 38

Slide 38 text

Command

Slide 39

Slide 39 text

Command

Slide 40

Slide 40 text

Chain of responsibility «Things in motion: Colored Domino» by Sigurd Decroos from http://www.sxc.hu/photo/1077403

Slide 41

Slide 41 text

Chain of responsibility ● Decouples the sender of a request from its receiver. ● The request is processed by the chain until some object handles it. Allows to: ● give more than one object a chance to handle the request.

Slide 42

Slide 42 text

Chain of responsibility

Slide 43

Slide 43 text

Chain of responsibility

Slide 44

Slide 44 text

Dependency injection «Tool Box & Levels» by Dylan Foley from http://www.flickr.com/photos/shoesfullofdust/3999374824/, available under a Creative Commons Attribution 2.0 Generic license: http://creativecommons.org/licenses/by/2.0/

Slide 45

Slide 45 text

Dependency injection ● Removes hard-coded dependencies. ● Provides a way to substitute dependencies. Allows to: ● choose among multiple implementations of a particular component, ● use mock implementations during unit testing.

Slide 46

Slide 46 text

Dependency injection

Slide 47

Slide 47 text

Dependency injection

Slide 48

Slide 48 text

«Cat And Dog» by Anna Langova from http://www.publicdomainpictures.net/view-image.php?image=24076, available under a Creative Commons CC0 1.0 Universal license: http://creativecommons.org/publicdomain/zero/1.0/

Slide 49

Slide 49 text

Thank you!