Slide 1

Slide 1 text

A resource orientated framework using the DI /AOP/REST Triangle

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

BEAR.Sunday is an application framework. But it offers no libraries. (We have good stuff)

Slide 4

Slide 4 text

ͦͷ୅ΘΓʹ̏ͭͷΦϒδΣΫτϑϨʔϜϫʔΫ DI AOP REST
 Instead, it offers three object frameworks.

Slide 5

Slide 5 text

What is a framework ?

Slide 6

Slide 6 text

ΤϯυϢʔβίʔυʹର͢ΔҰ࿈ͷઃܭ੍໿ ”imposes a set of design constraints on end-user code.”

Slide 7

Slide 7 text

Dependency Injection

Slide 8

Slide 8 text

ఆٛ DI͸ૄ݁߹ͷίʔσΟϯάΛՄೳʹ͢Διϑ τ΢ΤΞσβΠϯݪଇͱύλʔϯͷηοτ
 “Dependency Injection is a set of software design principles and patterns that enable you to develop loosely coupled code.”

Slide 9

Slide 9 text

ݪଇ ࣮૷Ͱ͸ͳ͘ɺ
 ΠϯλʔϑΣΠεʹରͯ͠ϓϩάϥϜ͢Δ
 Kent Beckand, Ward Cunningham 1987 Gang of Four 1994 “Program to an interface, not an implementation.”

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

GET SHIT DONE ! .. OK ? maintenance ? upgrade ?

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Ϧείϑͷஔ׵ݪଇ Liskov substitution principle

Slide 14

Slide 14 text

Decorator Pattern UPS

Slide 15

Slide 15 text

Composite Pattern

Slide 16

Slide 16 text

Null Object Pattern

Slide 17

Slide 17 text

Adapter Pattern

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

DIP: ґଘؔ܎ٯసͷݪଇ • ίʔυ͸ಉ౳Ҏ্ͷϨϕϧͷந৅ʹґଘ͢Δ • ԼҐϨϕϧͷৄࡉʹґଘ͠ͳ͍ • Code should depend on things that are at the same or higher level of abstraction • High level policy should not depend on low level details Dependency inversion principle

Slide 20

Slide 20 text

“ґଘੑٯసݪଇ͸ΦϒδΣΫτࢦ޲ٕज़ͷརӹͷࠜװΛͳ͢΋ͷɻ
 ࠶ར༻ΛՄೳʹ͢ΔϑϨʔϜϫʔΫͷ։ൃʹ͸ͦͷݪଇద༻͕ඞਢ” Robert Martin (a.k.a. Uncle Bob) “The principle of dependency inversion is at the root of many of the benefits claimed for object- oriented technology. Its proper application is necessary for the creation of reusable frameworks”

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

ந৅ʹґଘ্ͨ͠Ґίʔυ ᶃΠϯλʔϑΣΠεͰड͚औΓ ᶄϓϩύςΟʹ୅ೖ ᶅಡΈऔΓઐ༻ Higher-level code depends on abstraction passed through interface set to the property read-only

Slide 24

Slide 24 text

ந৅ʹ۩৅Λଋറ bind abstraction to concretion

Slide 25

Slide 25 text

ΦϒδΣΫτάϥϑੜ੒ building object graph

Slide 26

Slide 26 text

Billing
 Service Processor depends API Client Db Logger String lib Cal ? ? ΦϒδΣΫτάϥϑ object graph

Slide 27

Slide 27 text

Anti Pattern
 Dependency Lookup

Slide 28

Slide 28 text

Anti Pattern “MODE” ͍ͭ͘΋ͷύε खଓ͖Λίʔυ code “procedures” multiple execution path

Slide 29

Slide 29 text

ੜ੒ͱར༻͕෼཭ͨ͠DIύλʔϯ Compile Runtime ߏ଄Λίʔυ/ γϯάϧύε DI pattern code “structure” / single execution path

Slide 30

Slide 30 text


 Ͳ͜ͰΦϒδΣΫτάϥϑΛੜ੒͢Δ͔ʁ Where should we compose object graphs?

Slide 31

Slide 31 text

DI good practice
 ίʔυ͸ՄೳͳݶΓΠϯδΣΫλʔΛ௚઀ѻΘͳ͍ɻ
 ͦͷ୅ΘΓɺΞϓϦέʔγϣϯͷΤϯτϦʔϙΠϯτͰ̍ͭͷ ϧʔτΦϒδΣΫτΛੜ੒ͯ͠ΞϓϦέʔγϣϯΛىಈ͢Δ “Your code should deal directly with the Injector as little as possible. 
 Instead, you want to bootstrap your application by injecting one root object.”

Slide 32

Slide 32 text

Application = One Root Object

Slide 33

Slide 33 text

Application class

Slide 34

Slide 34 text

Application Script

Slide 35

Slide 35 text

Root Object

Slide 36

Slide 36 text

ͦΕͧΕͷґଘ͸อ࣋ͯ͠Δ͔อ࣋͞Ε͍ͯΔ͔ Dependencies have other dependencies Each object either contains or belongs to.

Slide 37

Slide 37 text

Live demo

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

print_o($obj);

Slide 40

Slide 40 text

ڊେɻ͔̍ͭ͠͠ͷม਺ͱͯ͠อଘՄೳɻ Huge, but can be stored one single value $app ϦΫΤετΛ௒͑ͯDI͕࠶ར༻Ͱ͖Δ Injection is reused beyond requests.

Slide 41

Slide 41 text

ϥϯλΠϜίϯύΠϧ΋ඞཁ • Ͳͷϖʔδ͔·ͩ෼͔Βͳ͍ • PDOΦϒδΣΫτ΍Ϋϩʔδϟ͸γϦΞϥΠζͰ ͖ͳ͍ Still, We need runtime compile No sure which page will be load Not everything can be serialized

Slide 42

Slide 42 text

Dependency Injection Compiler Compile

Slide 43

Slide 43 text

Instance script

Slide 44

Slide 44 text

• ֦ுੑ • ฒߦ։ൃ • ϝϯςφϯε • ςελϏϦςΟ • ΦϒδΣΫτͱར༻ͷੜ੒ͷ෼཭ • ΦϒδΣΫτσϦόϦʔ DIͷར఺ Extensibility Maintainability Parallel development Testability Clear separation of object instantiation and object usage Object delivery DI benefit

Slide 45

Slide 45 text

1st framework: DI Framework • DSLͱΞϊςʔγϣϯΛ࢖ͬͨDIϑϨʔϜϫʔΫ • ૄ݁߹ • ίϯύΠϧͱϥϯλΠϜͷ۠ผ • ΞϓϦέʔγϣϯ͸୯ҰͷΦϒδΣΫτ • CodegenͰߴ଎ loosely coupled compile time and runtime application root object DI framework with DSL w/ annotation fast

Slide 46

Slide 46 text

“Ray”

Slide 47

Slide 47 text

Aspect Oriented Programming

Slide 48

Slide 48 text

What is AOP? Cache Log Auth ԣஅతؔ৺ࣄΛ෼཭Մೳʹ͢Δ͜ͱʹΑΓ
 ϞδϡϥϦςΟʔΛ૿Ճͤ͞Δ͜ͱΛ໨తͱͨ͠
 ϓϩάϥϛϯάύϥμΠϜ A programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns

Slide 49

Slide 49 text

ॲཧ $a = microtime(true) microtime(true) - $a logic

Slide 50

Slide 50 text

ॲཧ BEGIN COMMIT

Slide 51

Slide 51 text

ॲཧ try catch

Slide 52

Slide 52 text

ॲཧ cache check save cache

Slide 53

Slide 53 text

ॲཧ cache check save cache ॲཧ ॲཧ

Slide 54

Slide 54 text

ຊ࣭తؔ৺ ԣஅతؔ৺

Slide 55

Slide 55 text

core concern cross cutting concern

Slide 56

Slide 56 text

Domain Logic Application Logic

Slide 57

Slide 57 text

Aspect Pattern before after around

Slide 58

Slide 58 text

Rock Concert Example

Slide 59

Slide 59 text

Gregor Kiczales

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

ϝιου࣮ߦ Caller Method method invocation

Slide 64

Slide 64 text

Πϯλʔηϓτ Caller Method Interceptor intercepting method

Slide 65

Slide 65 text

ෳ਺ͷΠϯλʔηϓτ C I I I M multiple interception

Slide 66

Slide 66 text

Hit Caller Method Cache Caller Method Cache Miss Ωϟογϡ͕͋Ε͹ϝιου͸ίʔϧ͞Εͳ͍ If the cache is warm the method is never called.

Slide 67

Slide 67 text

MethodInterceptor

Slide 68

Slide 68 text

Original method or next interceptor Cache Hit

Slide 69

Slide 69 text

Bind The Interceptor with Matcher

Slide 70

Slide 70 text

API Client

Slide 71

Slide 71 text

API Log Client Valid Auth

Slide 72

Slide 72 text

API Log !7BMJE BENJO %&-&5& Client Valid Auth

Slide 73

Slide 73 text

MVC, Is 3 enough ?

Slide 74

Slide 74 text

ՄมϨΠϠϦϯά Method Cache Form Auth Validation laying by context

Slide 75

Slide 75 text

PHPͰͷAOP࣮૷ํ๏ •Proxy (1.x) •Codegen (2.x) How to implement AOP in PHP

Slide 76

Slide 76 text

ܧঝΫϥεΛಈతʹੜ੒ͨ͠ܕ҆શͳΠϯλʔηϓτ Under the hood: Method interception sub class is created n order enable this interception and keep type safety.

Slide 77

Slide 77 text

2nd framework: Aspect Oriented Framework • AOPΞϥΠΞϯε • ίϯςΩετʹΑΔϨΠϠϦϯά • ܕ҆શ • CodegenͰߴ଎ AOP Alliance Laying by context Type safety Fast

Slide 78

Slide 78 text

Representational State Transfer

Slide 79

Slide 79 text

ϩΠɾϑΟʔϧσΟϯά

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

)551

Slide 84

Slide 84 text

$POTPMF

Slide 85

Slide 85 text

#&"34VOEBZ

Slide 86

Slide 86 text

1)1

Slide 87

Slide 87 text

1)1 $POTPMF )551 #&"3

Slide 88

Slide 88 text

Resource-Method-Representation

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

@Embed

Slide 93

Slide 93 text

HAL: Hypertext Application Language content-type: application/hal+json

Slide 94

Slide 94 text

Resource Graph User Profile @Embed Job Best Friend Office School

Slide 95

Slide 95 text

Inject Resource Parameter

Slide 96

Slide 96 text

Method base cache update

Slide 97

Slide 97 text

304 Not Modified

Slide 98

Slide 98 text

Content-Negotiation

Slide 99

Slide 99 text

OPTION method

Slide 100

Slide 100 text

JsonSchema Validation

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

Hypermedia

Slide 103

Slide 103 text

Payment hyperlink Hypermedia API Order

Slide 104

Slide 104 text

The key of success of web •URI •Unified Interface •Hyperlink

Slide 105

Slide 105 text

API APIۦಈ։ൃ DB Mobil e Web API Cloud Moc k URI API • API is hub • API is core value API driven development

Slide 106

Slide 106 text

No content

Slide 107

Slide 107 text

3rd framework: REST Framework • RESTfulͳϦιʔείϯςφ • HTTPඪ४ • ࠶ར༻ੑ • ڧྗͳΩϟογϡ RESTful container HTTP standard Reusability Cache-friendly

Slide 108

Slide 108 text

Performance • annotation ? dependency injection ? 
 method interception ? DSL ? named parameter ? • ߴ଎ • ΦϒδΣΫτάϥϑΩϟογϡ • Codegen Fast Object graph cache

Slide 109

Slide 109 text

Abstraction frameworks • DSL • Annotation • URI • Interface • Aspects • Hypermedia

Slide 110

Slide 110 text

Connecting frameworks • DI - ΦϒδΣΫτΛ݁Ϳ • AOP - Domain LogicͱApplication LogicΛ݁Ϳ • REST -ϦιʔεΛ݁Ϳ Connecting objects Connecting domain logic and application logic Connecting resources

Slide 111

Slide 111 text

No content

Slide 112

Slide 112 text

No content

Slide 113

Slide 113 text

AOP (Gregor Kiczales) DI (Martin Fowler) REST (Roy Fielding) OOP (Allan Kay) Annotation (Anders Hejlsberg) Guice (Bob Lee)

Slide 114

Slide 114 text

Why BEAR.Sunday ? • RESTfullΫϦʔϯΞʔΩςΫνϟ • APIۦಈ։ൃ • ࠶ར༻ੑ • ύϑΥʔϚϯε • ޙํޓ׵ RESTful clean architecture API driven development Reusability Performance NO BC break

Slide 115

Slide 115 text

Contributors

Slide 116

Slide 116 text

No content

Slide 117

Slide 117 text

No content

Slide 118

Slide 118 text

No content

Slide 119

Slide 119 text

@koriym @BEARSunday