Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Solid foundations for Rails apps
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Mariusz Lusiak
April 22, 2012
Programming
190
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Solid foundations for Rails apps
A talk given at Railsberry, the European Rails Conference, on Apr 20, 2012.
Mariusz Lusiak
April 22, 2012
More Decks by Mariusz Lusiak
See All by Mariusz Lusiak
OOP in Rails applications
mariuszlusiak
7
310
Other Decks in Programming
See All in Programming
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2k
Why Laravel apps break—Mastering the fundamentals to keep them maintainable
kentaroutakeda
1
350
These Five Tricks Can Make Your Apps Greener, Cheaper, & Nicer
hollycummins
0
280
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
3
1.3k
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
250
3Dシーンの圧縮
fadis
1
740
JavaDoc 再入門
nagise
0
320
Agentic UI
manfredsteyer
PRO
0
140
ふつうのFeature Flag実践入門
irof
7
3.7k
AIで効率化できた業務・日常
ochtum
0
120
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
710
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
150
Featured
See All Featured
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.6k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.1k
The Invisible Side of Design
smashingmag
302
52k
From π to Pie charts
rasagy
0
210
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
530
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
Fireside Chat
paigeccino
42
3.9k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
370
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
330
The Cult of Friendly URLs
andyhume
79
6.9k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
360
Transcript
Solid foundations for Rails apps
Love
A sip of frustration
OOP
ISP SRP DRY DI Liskov Open/Closed Least surprise Tell Don’t
Ask Law of Demeter Convention over Configuration Domain Language Capture
ISP SRP DRY DI Liskov Open/Closed Least surprise Tell Don’t
Ask Law of Demeter Convention over Configuration Domain Language Capture
SRP
Change
class User attr_reader :name def bandwidth_usage(month) # Calculate bandwidth usage
end end
class User attr_reader :name end class BandwidthUsage def initialize(user) user
= @user end def by_month(month) # Calculate bandwidth usage end end
Indicators
class Shipment def update_destination(name, address) @first_name, @last_name = name.split(' ')
@address = address end def update_last_name(name) @last_name = name.split(' ').last end end
class Shipment def update_destination(name, address) @first_name, @last_name = extract_names(name) @address
= address end def update_last_name(name) @last_name = extract_names(name).last end private def extract_names(name) name.split(' ') end end
class NameParser def initialize(name) # ... end def first_name #
... end def last_name # ... end end
class Shipment def update_destination(name, address) name_parser = NameParser.new(name) @first_name =
name_parser.first_name @last_name = name_parser.last_name @address = address end def update_last_name(name) name_parser = NameParser.new(name) @last_name = name_parser.last_name end end
Rails vs SRP
Active Record
Data Mapper
Solutions for AR
class User < ActiveRecord::Base include Favourites include Pictures include Organizations
include Embeddable include SocialProfiles # ... end
None
class Post < ActiveRecord::Base include FigLeaf hide ActiveRecord::Base, ancestors: true,
except: [Object, :init_with, :new_record?, :errors, :valid?, :save] hide_singletons ActiveRecord::Calculations, ActiveRecord::FinderMethods, # ...
Yet another reason
Is it easier to add a method to an existing
class or create a new class with that method?
Domain Language Capture
Writers
Coders
Managers, Helpers etc.
All the layers
Communication
None
1 class Tag 2 3 # ... 4 5 end
None
None
1 class Tag 2 3 # ... 4 5 end
Confusion
Unify naming, stay in sync
DRY
Model attributes, Partials, Routes
WET?
None
Knowledge
Comments
# Concatenates the salt with the password salt + password
# Concatenates the salt with the password (password + salt).hash
class User attr_accessor :admin end
user.admin = true
Name the business process
class User attr_accessor :admin def grant_admin_privileges @admin = true end
end
class GrantsAdminPrivileges def initialize(user) @user = user end def execute
@user.admin = true end end
SRP DLC DRY
@mariuszlusiak