• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Programming SOLID
 

Programming SOLID

on

  • 765 views

My

My

Statistics

Views

Total Views
765
Views on SlideShare
764
Embed Views
1

Actions

Likes
0
Downloads
1
Comments
0

1 Embed 1

https://twitter.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Programming SOLID Programming SOLID Presentation Transcript

  • S.O.L.I.D.applications Ladislav Martincik
  • Contents - Class, instance, object - DRY - S.O.L.I.D.ALL the time discussion please!
  • WHat is what? class Klass; end instance = Klass.new Object.new
  • SOLID- Single responsibility principle- Open/closed principle- Liskov substitution principle- Interface segregation principle- Dependency inversion principle
  • SINGLE RESP. P. object should have only a single responsibility - AR::Base - Presistency only - AR::Controller - REquest care only
  • 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
  • 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
  • SRP - Advancedclass User < AR::Baseendclass ArticleForSignup include ActiveModel::Validations validate :name, :presence => true attr_accessor :nameend
  • 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)
  • Ocp - basicclass Array def to_s self.map { |x| x.to_s }.join(, ) endend
  • Ocp - intermediateclass Invoice def to_s formater = HTMLFormater.new formater.format self endendclass Invoice def to_s formater = HTMLFormater.new formater.format self endend
  • Dependency Inj.depend upon abstractions, do not uponconcretions - link from outside in, not inside out
  • DI - BASICclass Error def initialize @reporter = Reporter.new end def report @reporter.report self endendclass Error def initialize reporter = Reporter.new @reporter = reporter endend
  • 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
  • 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
  • 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 ..>
  • Interface seg. many client specific interfaces are better than one general purpose interface - one smart controller
  • ISPclass Signup < ApplicationController def create if params[:type] == founder item = Founder.new(params) end ... endendclass FounderSignup < ApplicationControllerendclass AdvisorSignup < ApplicationControllerend
  • DRYDO not repeat the shit
  • 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.
  • 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.
  • 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?
  • 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.