Your SlideShare is downloading. ×
Programming SOLID
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Programming SOLID

499
views

Published on

My

My

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
499
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. S.O.L.I.D.applications Ladislav Martincik
    • 2. Contents - Class, instance, object - DRY - S.O.L.I.D.ALL the time discussion please!
    • 3. WHat is what? class Klass; end instance = Klass.new Object.new
    • 4. SOLID- Single responsibility principle- Open/closed principle- Liskov substitution principle- Interface segregation principle- Dependency inversion principle
    • 5. SINGLE RESP. P. object should have only a single responsibility - AR::Base - Presistency only - AR::Controller - REquest care only
    • 6. SRP - Basicclass User < AR::Base def can_modify_article? article article.user == self end before_save :create_activity def create_activity Activity.new :message => New user #{name} endend
    • 7. SRP - Basicclass User < AR::Base; endclass ArticlePolicy def can_user_modify_article? user, article article.user == user endendclass UserObserver def after_save record Activity.new :message => New user #{record.name} endend
    • 8. SRP - Advancedclass User < AR::Baseendclass ArticleForSignup include ActiveModel::Validations validate :name, :presence => true attr_accessor :nameend
    • 9. OPEn/close p.an object should be open forextensions but close for modifications - ruby is dynamic lang. so modifying object is its nature - meta-programming (use with care)
    • 10. Ocp - basicclass Array def to_s self.map { |x| x.to_s }.join(, ) endend
    • 11. Ocp - intermediateclass Invoice def to_s formater = HTMLFormater.new formater.format self endendclass Invoice def to_s formater = HTMLFormater.new formater.format self endend
    • 12. Dependency Inj.depend upon abstractions, do not uponconcretions - link from outside in, not inside out
    • 13. DI - BASICclass Error def initialize @reporter = Reporter.new end def report @reporter.report self endendclass Error def initialize reporter = Reporter.new @reporter = reporter endend
    • 14. DI - More abstractclass Error def initialize(options = {}) @reporter = options[:reporter] || Reporter.new endendclass Error def initialize(options = {}) @reporter = (options[:reporter_name] || reporter).classify.new endend
    • 15. Liskov D. P. objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program - method missing - super-class is smarter than its children
    • 16. Liskov - AR::Baseclass User < AR::Base # create_table :users { |t| t.text :logger }end# We expect ...user = User.newuser.logger = "syslog-ng"# => "syslog-ng"# but we getuser = User.newuser.logger = "syslog-ng"# => #<ActiveSupport::BufferedLogger:0x00000000b6de38 ..>
    • 17. Interface seg. many client specific interfaces are better than one general purpose interface - one smart controller
    • 18. ISPclass Signup < ApplicationController def create if params[:type] == founder item = Founder.new(params) end ... endendclass FounderSignup < ApplicationControllerendclass AdvisorSignup < ApplicationControllerend
    • 19. DRYDO not repeat the shit
    • 20. Why?If your application is successful youwill have to change it as newrequirements will come or newimprovements will be introduced.Refactor not because you know theabstraction but because you wantto find it.
    • 21. REality 2 imp. Customers should come to you with specific, tangible, measurable, external objectives that you can than implement and come up with abstractions. The reason is because people relate very well to concrete stuff in our world then to abstract, emotional descriptions.
    • 22. examples - Make my customers feel more happy, What means more happy? - The signup has to be simple. What it means simple? - I need more leads/customers to come to my shop.. How do you measure more?
    • 23. Best practice The path from abstract descriptions of our customers to concrete examples and back to abstract concepts so we can change stuff easily in future.