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
Mariusz Lusiak
April 22, 2012
Programming
4
180
Solid foundations for Rails apps
A talk given at Railsberry, the European Rails Conference, on Apr 20, 2012.
Mariusz Lusiak
April 22, 2012
Tweet
Share
More Decks by Mariusz Lusiak
See All by Mariusz Lusiak
OOP in Rails applications
mariuszlusiak
7
300
Other Decks in Programming
See All in Programming
Discover Metal 4
rei315
2
130
A full stack side project webapp all in Kotlin (KotlinConf 2025)
dankim
0
110
AIエージェントはこう育てる - GitHub Copilot Agentとチームの共進化サイクル
koboriakira
0
510
LT 2025-06-30: プロダクトエンジニアの役割
yamamotok
0
730
AI時代のソフトウェア開発を考える(2025/07版) / Agentic Software Engineering Findy 2025-07 Edition
twada
PRO
76
25k
0626 Findy Product Manager LT Night_高田スライド_speaker deck用
mana_takada
0
160
「Cursor/Devin全社導入の理想と現実」のその後
saitoryc
0
790
地方に住むエンジニアの残酷な現実とキャリア論
ichimichi
5
1.5k
テストから始めるAgentic Coding 〜Claude Codeと共に行うTDD〜 / Agentic Coding starts with testing
rkaga
11
3k
GraphRAGの仕組みまるわかり
tosuri13
8
530
チームのテスト力を総合的に鍛えて品質、スピード、レジリエンスを共立させる/Testing approach that improves quality, speed, and resilience
goyoki
4
730
Systèmes distribués, pour le meilleur et pour le pire - BreizhCamp 2025 - Conférence
slecache
0
120
Featured
See All Featured
How to Ace a Technical Interview
jacobian
277
23k
Agile that works and the tools we love
rasmusluckow
329
21k
Raft: Consensus for Rubyists
vanstee
140
7k
GraphQLとの向き合い方2022年版
quramy
49
14k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.7k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
Making Projects Easy
brettharned
116
6.3k
Thoughts on Productivity
jonyablonski
69
4.7k
Building a Modern Day E-commerce SEO Strategy
aleyda
42
7.4k
Building Applications with DynamoDB
mza
95
6.5k
Typedesign – Prime Four
hannesfritz
42
2.7k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
18
960
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