Skip to content

Instantly share code, notes, and snippets.

@kevinlebrun
Last active September 28, 2018 02:51
Show Gist options
  • Save kevinlebrun/3155854 to your computer and use it in GitHub Desktop.
Save kevinlebrun/3155854 to your computer and use it in GitHub Desktop.
Principles of Object Oriented Design

Principles

  • DRY ou Don't Repeat Yourself
  • KISS ou Keep It Simple, Stupid!
  • YAGNI ou You Ain't Gonna Need It!
  • SOLID
  • STUPID
  • Law Of Demeter
  • Tell, don't ask!

SOLID

  • Single Responsability Principle
  • Open/Close Principle
  • Liskov Substitution Principle
  • Interface Segregation Principle
  • Dependency Inversion Principle

STUPID

  • Singleton (Static)
  • Tight Coupling
  • Untestable
  • Premature Optimization
  • Indescriptive Naming
  • Duplication

GRASP (General Responsibility Assignment Software Principles)

  • Information Expert
  • Creator
  • Controller
  • Low Coupling
  • High Cohesion
  • Polymorphism
  • Pure Fabrication
  • Indirection
  • Protected Variations

Object Calisthenics

  • Use only one level of indentation per method.
  • Don't use the else keyword.
  • Wrap all primitives and strings.
  • Use only one dot per line.
  • Don't abbreviate.
  • Keep all entities small.
  • Don't use any classes with more than two instance variables.
  • Use first-class collections.
  • Don't use any getters/setters/properties.

Sandi Metz’ rules for developers

http://robots.thoughtbot.com/post/50655960596/sandi-metz-rules-for-developers?utm_source=rubyweekly&utm_medium=email

  • Classes can be no longer than one hundred lines of code.
  • Methods can be no longer than five lines of code.
  • Pass no more than four parameters into a method. Hash options are parameters.
  • Controllers can instantiate only one object. Therefore, views can only know about one instance variable and views should only send messages to that object (@object.collaborator.value is not allowed).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment