Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
@gotar | @oskarszrajer gotar.info
Oskar Szrajer
Beyond MVC
(How to write a good code)
MVC
(Model View Controller)
Fat controller
Fat model
identifying problems
• long files (classes)
• SRP (Single Responsibility Principle)
• Law of Demeter (Principle of Least Kn...
7 patterns to help You
• Value Objects
• Service Objects
• Form Objects
• Query Objects
• View Objects
• Policy Objects
• ...
Service Objects
class ResetPassword
attr_reader :id
def initialize(id)
@id = id
end
def call
...
end
end
ResetPassword.new(1).call
class ResetPassword
attr_reader :id
def initialize(id)
@id = id
end
def call
...
end
def self.call(*p)
new(*p).call
end
en...
Q&A
@gotar | @oskarszrajer gotar.info
Summer 2016 Interns
http://summer2016.ragnarson.com/
TRUG
(Trójmiasto Ruby User Group)
http://trug.pl
Thx
@gotar | @oskarszrajer gotar.info
Beyond MVC
Beyond MVC
Upcoming SlideShare
Loading in …5
×

Beyond MVC

112 views

Published on

How to write a good scalable code. 7 patterns to refactor fat model.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Beyond MVC

  1. 1. @gotar | @oskarszrajer gotar.info Oskar Szrajer
  2. 2. Beyond MVC (How to write a good code)
  3. 3. MVC (Model View Controller)
  4. 4. Fat controller
  5. 5. Fat model
  6. 6. identifying problems • long files (classes) • SRP (Single Responsibility Principle) • Law of Demeter (Principle of Least Knowledge) • complex tests • callbacks
  7. 7. 7 patterns to help You • Value Objects • Service Objects • Form Objects • Query Objects • View Objects • Policy Objects • Decorators http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/
  8. 8. Service Objects
  9. 9. class ResetPassword attr_reader :id def initialize(id) @id = id end def call ... end end ResetPassword.new(1).call
  10. 10. class ResetPassword attr_reader :id def initialize(id) @id = id end def call ... end def self.call(*p) new(*p).call end end ResetPassword.call(1)
  11. 11. Q&A @gotar | @oskarszrajer gotar.info
  12. 12. Summer 2016 Interns http://summer2016.ragnarson.com/
  13. 13. TRUG (Trójmiasto Ruby User Group) http://trug.pl
  14. 14. Thx @gotar | @oskarszrajer gotar.info

×