Slide 1

Slide 1 text

TREATING OBJECTS LIKE PEOPLE @mattwynne | @baruco | Setiembre 2013

Slide 2

Slide 2 text

(c) David Shrigley

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

2008

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

2012

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Feature: Update card details Need to be able to update my card, e.g. if I decide to use a different one for billing. Scenario: Update card details successfully Given I have started a paid subscription on the pro plan When I choose to update which card is billed Then I should see that my card details have been saved Scenario: Use a bad card Given I have started a paid subscription on the pro plan When I try to change to an invalid card Then I should see that my card has been declined

Slide 14

Slide 14 text

Feature Scenario Step * * Formatter

Slide 15

Slide 15 text

Result

Slide 16

Slide 16 text

Feature Scenario Formatter Step accept(self) before_feature accept(formatter) before_scenario accept(formatter) before_step after_step after_scenario after_feature execute(step)

Slide 17

Slide 17 text

Feature: Update card details Need to be able to update my card, e.g. if I decide to use a different one for billing. Scenario: Update card details successfully Given I have started a paid subscription on the pro plan When I choose to update which card is billed Then I should see that my card details have been saved Scenario: Use a bad card Given I have started a paid subscription on the pro plan When I try to change to an invalid card Then I should see that my card has been declined

Slide 18

Slide 18 text

Feature: Update card details Need to be able to update my card, e.g. if I decide to use a different one for billing. Scenario: Update card details successfully Given I have started a paid subscription on the pro plan When I choose to update which card is billed Then I should see that my card details have been saved Scenario: Use a bad card Given I have started a paid subscription on the pro plan When I try to change to an invalid card Then I should see that my card has been declined

Slide 19

Slide 19 text

Feature: Update card details Need to be able to update my card, e.g. if I decide to use a different one for billing. Background: Given I have started a paid subscription on the pro plan Scenario: Update card details successfully When I choose to update which card is billed Then I should see that my card details have been saved Scenario: Use a bad card When I try to change to an invalid card Then I should see that my card has been declined

Slide 20

Slide 20 text

Feature Scenario Step * * Background Step * 0..1

Slide 21

Slide 21 text

Feature: Update card details Need to be able to update my card, e.g. if I decide to use a different one for billing. Scenario Outline: Update card details Given I have started a paid subscription on the pro plan When I update my card details with a card Then I should see "" Examples: | card status | message | | valid | Your card details have been saved. | | expired | This card has expired. | | stolen | The police are on their way. |

Slide 22

Slide 22 text

Feature Scenario Step * * Background Step * 0..1 Scenario Outline Step * * Example *

Slide 23

Slide 23 text

module Cucumber module Ast class Background def accept(visitor) return if @already_visited visitor.visit_background(self) do comment.accept(visitor) visitor.visit_background_name(@keyword, name, file_colon_li with_visitor(feature_elements.first || self, visitor) do visitor.runtime.before(hook_context) skip_invoke! if failed? step_invocations.accept(visitor) @failed = step_invocations.any? do |step_invocation| step_invocation.exception || step_invocation.status != :passed end if @failed || feature_elements.empty? visitor.runtime.after(hook_context) end end end @already_visited = true end

Slide 24

Slide 24 text

Our First Mistake: Data-Centric Domain Model

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

Problem Domain Solution Domain

Slide 27

Slide 27 text

"Model the problem domain and the solution will take care of itself." DAVID WEST, OBJECT THINKING

Slide 28

Slide 28 text

1967

Slide 29

Slide 29 text

SIMULA 67 1967 http://www.jot.fm/issues/issue_2002_09/eulogy/

Slide 30

Slide 30 text

"It should be problem oriented and not computer oriented, even if this implies an appreciable increase in the amount of work that has to be done by the computer" SIMULA 67 1967 http://www.jot.fm/issues/issue_2002_09/eulogy/

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

1979

Slide 33

Slide 33 text

C++ 1979 "SIMULA's class-based system was a huge plus, but it's run-time performance was hopeless."

Slide 34

Slide 34 text

SMALLTALK-80 Called "Smalltalk"--as in "programming should be a matter of ..." [Smalltalk] and "children should program in ..." [Smalltalk]. -- Alan Kay 1980

Slide 35

Slide 35 text

SIMULA 67 1967 C++ 1979 Smalltalk-80 1980

Slide 36

Slide 36 text

Two philosophies

Slide 37

Slide 37 text

Two cultures

Slide 38

Slide 38 text

C++ Smalltalk-80

Slide 39

Slide 39 text

"Good" OOP "Bad" OOP FOCUS ON DATA FOCUS ON MESSAGES FOCUS ON BEHAVIOUR, RESPONSIBILITIES FOCUS ON STRUCTURE, LAYERS ABSORBED IN THE PROBLEM DISTRACTED BY THE SOLUTION CULTURE OF FLEXIBILITY, COLLABORATION, FUN, CHAOS CULTURE OF FORMALITY, HIERARCHY, CENTRALISED CONTROL

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

2.0

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Our first fix: A responsibility-centric model

Slide 44

Slide 44 text

Compiler Runner Parser Report

Slide 45

Slide 45 text

A design principle: Tell objects, ask values* * (thank GOOS)

Slide 46

Slide 46 text

Compiler Runner Parser feature scenario step test_case step scenario step step test_case

Slide 47

Slide 47 text

Compiler Runner test_case Report before_test_case(case) after_test_case(case, result) before_test_step(step) after_test_step(step, result) execute(step)

Slide 48

Slide 48 text

LESS STATE, LESS BUGS

Slide 49

Slide 49 text

YOUR PROGRAMS ARE PROBABLY TOO STUPID TO BE ALLOWED TO REMEMBER STUFF

Slide 50

Slide 50 text

So remember... MODEL ACTIVITY, THEN PUSH DATA THROUGH THAT MODEL MAKE YOUR DATA IMMUTABLE TELL OBJECTS, ASK VALUES TREAT OBJECTS LIKE PEOPLE

Slide 51

Slide 51 text

http://cucumber.pro