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
190
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
310
Other Decks in Programming
See All in Programming
CopilotKit + AG-UIを学ぶ
nearme_tech
PRO
2
140
Codexに役割を持たせる 他のAIエージェントと組み合わせる実務Tips
o8n
3
1.1k
エージェント開発初心者の僕がエージェントを作った話と今後やりたいこと
thasu0123
0
230
DevinとClaude Code、SREの現場で使い倒してみた件
karia
1
970
Agent Skills Workshop - AIへの頼み方を仕組み化する
gotalab555
15
8.2k
encoding/json/v2のUnmarshalはこう変わった:内部実装で見る設計改善
kurakura0916
0
350
nuget-server - あなたが必要だったNuGetサーバー
kekyo
PRO
0
200
NOT A HOTEL - 建築や人と融合し、自由を創り出すソフトウェア
not_a_hokuts
2
590
手戻りゼロ? Spec Driven Developmentとは@KAG AI week
tmhirai
1
170
Go1.26 go fixをプロダクトに適用して困ったこと
kurakura0916
0
330
ベクトル検索のフィルタを用いた機械学習モデルとの統合 / python-meetup-fukuoka-06-vector-attr
monochromegane
2
340
CSC307 Lecture 13
javiergs
PRO
0
310
Featured
See All Featured
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.1k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
660
How to build a perfect <img>
jonoalderson
1
5.2k
Test your architecture with Archunit
thirion
1
2.2k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
66
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
60
42k
The Invisible Side of Design
smashingmag
302
51k
Google's AI Overviews - The New Search
badams
0
930
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
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