You Used To Inject Me In Your Constructor

52
You Used To Inject Me In Your Constructor - Functional Programming In Swift

Transcript of You Used To Inject Me In Your Constructor

You Used To Inject Me In Your Constructor

- Functional Programming In Swift

Hello, I’m Veronica Ray!

–Dependency Injection Demystified

“Dependency injection means giving an object its

instance variables. Really.

That's it.”

WHY

WHY•Clear declaration of dependencies

•Composition •Easy customization

WHY

•Clear ownership

•Testability

FRAMEWORK

LAYER OF ABSTRACTION

SUPER LINEAR

SMART FRAMEWORKS

LAZY EVALUATION

–HaskellWiki

“…expressions are not evaluated when they are

bound to variables, but their evaluation is deferred until their results are needed by

other computations. ”

–HaskellWiki

“…Pure computations ..can be performed at any time and still yield the same

result.

–HaskellWiki

“This makes it possible to defer the computation of

values until they are needed, that is, to compute

them lazily. ”

Lazy evaluationBrought to you by functional programming

MEMOIZATION

–Python 3 Tutorial

“ If the same input or a function call with the same

parameters is used, the previously stored results can

be used again and unnecessary calculation are

avoided.”

SCOPES

TYPHOON

TyphoonScopeSingletonTyphoonScopeLazySingleton

SWINJECT

ObjectScope.Container

ISSUES

WE NEED A RESOLUTION

DI IN SWIFT

•constructor injection

•reader monad

DI IN SWIFT

•constructor injection

•reader monad

BearWithMeFind fiends to hibernate with

during the winter

–In today’s post-OO world, is dependency injection still relevant?

“Currently we use the same mechanism – parameters – to define the environment

(e.g. via constructor parameters), as we use to

pass data around functions.”

DI IN SWIFT

•constructor injection

•reader monad

–Don’t Fear The Reader

“…if you break down common dependency

injection libraries they are just different

implementations of the Reader Monad pattern.”

SIMPLE EXAMPLE

DO NOTATION

DESUGARED

SWIFT

BearWithMeFind fiends to hibernate with

during the winter

IS THIS A GOOD IDEA?

USE DEPENDENCY INJECTION

LEARN MORE

•Swiftz •Swift Injection •Nick Santos •objc.io •adit.io

THANK YOU