1 of 15

Isolating Boundaries

Andrei Lisnic (@andrei_lisnic)

2 of 15

We are programmers

we translate ideas into code

3 of 15

Idea code

because we can think on different levels

of abstraction

4 of 15

Leaky abstractions

5 of 15

A well-designed system

Has well defined boundaries between its levels of abstraction

6 of 15

7 of 15

Single responsibility

a object should have only one reason to change

8 of 15

Single responsibility

class Email

def get_content

end

...

def draw

end

end

9 of 15

Single responsibility

good bad

class Email

def get_content

end

...

def draw

end

end

class Email

def get_content

end

...

end

class EmailView

def draw

end

end

10 of 15

Constants

class UserRepository

def all

JSON.parse RestClient.get(“http://somehost/api/users/”)

end

#...other methods that use http://somehost/api/users/

end

11 of 15

Constants

class UserRepository

USERS_URL = “http://somehost/api/users/

def all

JSON.parse RestClient.get(USERS_URL)

end

end

12 of 15

class UserRepository

USERS_URL = “http://somehost/api/users/

def all

parse(get(USERS_URL))

end

...

private

def parse response

JSON.parse response

end

def get url

RestClient.get

end

end

13 of 15

Functional data manipulation

def users_with_not_recommended_reports

hospital.reports.created_today

.with_score_bigger(0.5)

.not_aproved

.map(&:user)

.uniq

end

14 of 15

- Don’t copy/paste code, build simple interfaces

- Don’t find and replace, give names to things

15 of 15

Thank you