SlideShare a Scribd company logo
1 of 23
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 - Basic
class 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}'
  end
end
SRP - Basic
class User < AR::Base; end

class ArticlePolicy
  def can_user_modify_article? user, article
    article.user == user
  end
end

class UserObserver
  def after_save record
    Activity.new :message => 'New user #{record.name}'
  end
end
SRP - Advanced
class User < AR::Base
end

class ArticleForSignup
  include ActiveModel::Validations

  validate :name, :presence => true

  attr_accessor :name
end
OPEn/close p.
an object should be open for
extensions but close for modifications

  - ruby is dynamic lang. so modifying
  object is its nature
  - meta-programming (use with care)
Ocp - basic
class Array
  def to_s
    self.map { |x| x.to_s }.join(', ')
  end
end
Ocp - intermediate
class Invoice
  def to_s
    formater = HTMLFormater.new
    formater.format self
  end
end

class Invoice
  def to_s formater = HTMLFormater.new
    formater.format self
  end
end
Dependency Inj.
depend upon abstractions, do not upon
concretions


  - link from outside in, not inside out
DI - BASIC
class Error
  def initialize
    @reporter = Reporter.new
  end

  def report
    @reporter.report self
  end
end

class Error
  def initialize reporter = Reporter.new
    @reporter = reporter
  end
end
DI - More abstract
class Error
  def initialize(options = {})
    @reporter = options[:reporter] || Reporter.new
  end
end



class Error
  def initialize(options = {})
    @reporter = (options[:reporter_name] || 'reporter').classify.new
  end
end
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::Base
class User < AR::Base
  # create_table :users { |t| t.text :logger }
end

# We expect ...
user = User.new
user.logger = "syslog-ng"
# => "syslog-ng"

# but we get
user = User.new
user.logger = "syslog-ng"
# => #<ActiveSupport::BufferedLogger:0x00000000b6de38 ..>
Interface seg.
 many client specific interfaces are
 better than one general purpose
 interface



   - one smart controller
ISP
class Signup < ApplicationController

  def create
    if params[:type] == 'founder'
      item = Founder.new(params)
    end

    ...
  end

end

class FounderSignup < ApplicationController
end

class AdvisorSignup < ApplicationController
end
DRY
DO not repeat the shit
Why?
If your application is successful you
will have to change it as new
requirements will come or new
improvements will be introduced.

Refactor not because you know the
abstraction but because you want
to 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.

More Related Content

What's hot

Introduction to JSX
Introduction to JSXIntroduction to JSX
Introduction to JSXMicah Wood
 
Basics of Javascript
Basics of Javascript Basics of Javascript
Basics of Javascript poojanov04
 
Chapter 4.2
Chapter 4.2Chapter 4.2
Chapter 4.2sotlsoc
 
Designing function families and bundles with java's behaviors parameterisatio...
Designing function families and bundles with java's behaviors parameterisatio...Designing function families and bundles with java's behaviors parameterisatio...
Designing function families and bundles with java's behaviors parameterisatio...Alain Lompo
 
Deep Dive into Swift Literal
Deep Dive into Swift LiteralDeep Dive into Swift Literal
Deep Dive into Swift Literal秋 勇紀
 
Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Jalpesh Vasa
 
Dependency Injection and Pimple
Dependency Injection and PimpleDependency Injection and Pimple
Dependency Injection and PimpleDQNEO
 
Function overloading in c++
Function overloading in c++Function overloading in c++
Function overloading in c++Learn By Watch
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Javayzebelle
 

What's hot (16)

Introduction to JSX
Introduction to JSXIntroduction to JSX
Introduction to JSX
 
Php assignment help
Php assignment helpPhp assignment help
Php assignment help
 
Basics of Javascript
Basics of Javascript Basics of Javascript
Basics of Javascript
 
Chapter 4.2
Chapter 4.2Chapter 4.2
Chapter 4.2
 
Functions in php
Functions in phpFunctions in php
Functions in php
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Designing function families and bundles with java's behaviors parameterisatio...
Designing function families and bundles with java's behaviors parameterisatio...Designing function families and bundles with java's behaviors parameterisatio...
Designing function families and bundles with java's behaviors parameterisatio...
 
Deep Dive into Swift Literal
Deep Dive into Swift LiteralDeep Dive into Swift Literal
Deep Dive into Swift Literal
 
Effective PHP. Part 6
Effective PHP. Part 6Effective PHP. Part 6
Effective PHP. Part 6
 
Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1
 
Dependency Injection and Pimple
Dependency Injection and PimpleDependency Injection and Pimple
Dependency Injection and Pimple
 
Function overloading in c++
Function overloading in c++Function overloading in c++
Function overloading in c++
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Unit 2.5
Unit 2.5Unit 2.5
Unit 2.5
 
Java script
Java scriptJava script
Java script
 

Viewers also liked

Don't be STUPID, Grasp SOLID - North East PHP
Don't be STUPID, Grasp SOLID - North East PHPDon't be STUPID, Grasp SOLID - North East PHP
Don't be STUPID, Grasp SOLID - North East PHPAnthony Ferrara
 
Don't Be STUPID, Grasp SOLID - ConFoo Edition
Don't Be STUPID, Grasp SOLID - ConFoo EditionDon't Be STUPID, Grasp SOLID - ConFoo Edition
Don't Be STUPID, Grasp SOLID - ConFoo EditionAnthony Ferrara
 
SOLID Principles of Refactoring Presentation - Inland Empire User Group
SOLID Principles of Refactoring Presentation - Inland Empire User GroupSOLID Principles of Refactoring Presentation - Inland Empire User Group
SOLID Principles of Refactoring Presentation - Inland Empire User GroupAdnan Masood
 
SOLID -Clean Code For Mere Mortals
SOLID -Clean Code For Mere MortalsSOLID -Clean Code For Mere Mortals
SOLID -Clean Code For Mere MortalsWekoslav Stefanovski
 

Viewers also liked (6)

Don't be STUPID, Grasp SOLID - North East PHP
Don't be STUPID, Grasp SOLID - North East PHPDon't be STUPID, Grasp SOLID - North East PHP
Don't be STUPID, Grasp SOLID - North East PHP
 
Don't Be STUPID, Grasp SOLID - ConFoo Edition
Don't Be STUPID, Grasp SOLID - ConFoo EditionDon't Be STUPID, Grasp SOLID - ConFoo Edition
Don't Be STUPID, Grasp SOLID - ConFoo Edition
 
People Pattern Power
People Pattern PowerPeople Pattern Power
People Pattern Power
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
SOLID Principles of Refactoring Presentation - Inland Empire User Group
SOLID Principles of Refactoring Presentation - Inland Empire User GroupSOLID Principles of Refactoring Presentation - Inland Empire User Group
SOLID Principles of Refactoring Presentation - Inland Empire User Group
 
SOLID -Clean Code For Mere Mortals
SOLID -Clean Code For Mere MortalsSOLID -Clean Code For Mere Mortals
SOLID -Clean Code For Mere Mortals
 

Similar to Programming SOLID

O365 Saturday - Deepdive SharePoint Client Side Rendering
O365 Saturday - Deepdive SharePoint Client Side RenderingO365 Saturday - Deepdive SharePoint Client Side Rendering
O365 Saturday - Deepdive SharePoint Client Side RenderingRiwut Libinuko
 
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...Coupa Software
 
Object Oriented Analysis and Design with UML2 part2
Object Oriented Analysis and Design with UML2 part2Object Oriented Analysis and Design with UML2 part2
Object Oriented Analysis and Design with UML2 part2Haitham Raik
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Railsrstankov
 
Structuring An ABAP Report In An Optimal Way
Structuring An ABAP Report In An Optimal WayStructuring An ABAP Report In An Optimal Way
Structuring An ABAP Report In An Optimal WayBlackvard
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)James Titcumb
 
Maintaining legacy applications
Maintaining legacy applicationsMaintaining legacy applications
Maintaining legacy applicationsXethron
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in phpCPD INDIA
 
OOP-Advanced Programming with c++
OOP-Advanced Programming with c++OOP-Advanced Programming with c++
OOP-Advanced Programming with c++Mohamed Essam
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)Chiew Carol
 
Basic Oops concept of PHP
Basic Oops concept of PHPBasic Oops concept of PHP
Basic Oops concept of PHPRohan Sharma
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principlesdeonpmeyer
 
design-principles.ppt
design-principles.pptdesign-principles.ppt
design-principles.pptWalidLahsiki
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterSachin G Kulkarni
 
Solid - OOD Principles
Solid - OOD PrinciplesSolid - OOD Principles
Solid - OOD PrinciplesCreditas
 

Similar to Programming SOLID (20)

O365 Saturday - Deepdive SharePoint Client Side Rendering
O365 Saturday - Deepdive SharePoint Client Side RenderingO365 Saturday - Deepdive SharePoint Client Side Rendering
O365 Saturday - Deepdive SharePoint Client Side Rendering
 
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
 
Object Oriented Analysis and Design with UML2 part2
Object Oriented Analysis and Design with UML2 part2Object Oriented Analysis and Design with UML2 part2
Object Oriented Analysis and Design with UML2 part2
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
Structuring An ABAP Report In An Optimal Way
Structuring An ABAP Report In An Optimal WayStructuring An ABAP Report In An Optimal Way
Structuring An ABAP Report In An Optimal Way
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
 
Maintaining legacy applications
Maintaining legacy applicationsMaintaining legacy applications
Maintaining legacy applications
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
 
OOP-Advanced Programming with c++
OOP-Advanced Programming with c++OOP-Advanced Programming with c++
OOP-Advanced Programming with c++
 
The Rails Way
The Rails WayThe Rails Way
The Rails Way
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
 
Oops in php
Oops in phpOops in php
Oops in php
 
Introduction Php
Introduction PhpIntroduction Php
Introduction Php
 
Basic Oops concept of PHP
Basic Oops concept of PHPBasic Oops concept of PHP
Basic Oops concept of PHP
 
Object Oriented Concepts and Principles
Object Oriented Concepts and PrinciplesObject Oriented Concepts and Principles
Object Oriented Concepts and Principles
 
design-principles.ppt
design-principles.pptdesign-principles.ppt
design-principles.ppt
 
Clean Code
Clean CodeClean Code
Clean Code
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in Codeigniter
 
Solid - OOD Principles
Solid - OOD PrinciplesSolid - OOD Principles
Solid - OOD Principles
 
AngularJS Basic Training
AngularJS Basic TrainingAngularJS Basic Training
AngularJS Basic Training
 

More from Ladislav Martincik (7)

Productivity
ProductivityProductivity
Productivity
 
Trable programatora
Trable programatoraTrable programatora
Trable programatora
 
Efektivní učení
Efektivní učeníEfektivní učení
Efektivní učení
 
6 pillars of business
6 pillars of business6 pillars of business
6 pillars of business
 
Super Projects
Super ProjectsSuper Projects
Super Projects
 
Super kariera
Super karieraSuper kariera
Super kariera
 
Super team
Super teamSuper team
Super team
 

Recently uploaded

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 

Recently uploaded (20)

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 

Programming SOLID

  • 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 - Basic class 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}' end end
  • 7. SRP - Basic class User < AR::Base; end class ArticlePolicy def can_user_modify_article? user, article article.user == user end end class UserObserver def after_save record Activity.new :message => 'New user #{record.name}' end end
  • 8. SRP - Advanced class User < AR::Base end class ArticleForSignup include ActiveModel::Validations validate :name, :presence => true attr_accessor :name end
  • 9. OPEn/close p. an object should be open for extensions but close for modifications - ruby is dynamic lang. so modifying object is its nature - meta-programming (use with care)
  • 10. Ocp - basic class Array def to_s self.map { |x| x.to_s }.join(', ') end end
  • 11. Ocp - intermediate class Invoice def to_s formater = HTMLFormater.new formater.format self end end class Invoice def to_s formater = HTMLFormater.new formater.format self end end
  • 12. Dependency Inj. depend upon abstractions, do not upon concretions - link from outside in, not inside out
  • 13. DI - BASIC class Error def initialize @reporter = Reporter.new end def report @reporter.report self end end class Error def initialize reporter = Reporter.new @reporter = reporter end end
  • 14. DI - More abstract class Error def initialize(options = {}) @reporter = options[:reporter] || Reporter.new end end class Error def initialize(options = {}) @reporter = (options[:reporter_name] || 'reporter').classify.new end end
  • 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::Base class User < AR::Base # create_table :users { |t| t.text :logger } end # We expect ... user = User.new user.logger = "syslog-ng" # => "syslog-ng" # but we get user = User.new user.logger = "syslog-ng" # => #<ActiveSupport::BufferedLogger:0x00000000b6de38 ..>
  • 17. Interface seg. many client specific interfaces are better than one general purpose interface - one smart controller
  • 18. ISP class Signup < ApplicationController def create if params[:type] == 'founder' item = Founder.new(params) end ... end end class FounderSignup < ApplicationController end class AdvisorSignup < ApplicationController end
  • 19. DRY DO not repeat the shit
  • 20. Why? If your application is successful you will have to change it as new requirements will come or new improvements will be introduced. Refactor not because you know the abstraction but because you want to 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.

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n