Skip to content

Instantly share code, notes, and snippets.

@sleeptillseven
Created November 22, 2012 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sleeptillseven/4129703 to your computer and use it in GitHub Desktop.
Save sleeptillseven/4129703 to your computer and use it in GitHub Desktop.
Object-Oriented Design in Ruby
# Dependency Management
## Dependency
* Should be exposed explicitly
* Should be isolated
* Should be exposed in an own method
## Interaction Between Objects/Interfaces
* Objects should be as loosely coupled as possbile
* Objects should have to know as less as possbile about other objects
* Build on less likely to change dependencies first
## Arguments
* Avoid order
* Try to use hashes
* Use clear names for keys
* Handle defaults

Single Responsibility

Class

  • Should do the smallest thing possible
  • Should be described by a noun
  • What it does should be intuitively linked to its name
  • Should be small
  • Should be easy to reuse

Method

  • Should have a single responsibility
  • Should be short
  • Should be reusable

Variables

  • Hide instance variables
  • Use attr_accessor etc.

Data

  • Hide structure
  • Use Struct or a new class to represent data if it make sense
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment