Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
430 lines (414 sloc) 18.3 KB
<!DOCTYPE html>
<title>Don't Be Stupid, Grasp Solid</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="assets/js/jquery.js"></script>
<script type="text/javascript" src="assets/js/"></script>
<script type="text/javascript" src="assets/js/"></script>
<script type="text/javascript" src="assets/js/jquery.hashchange.js"></script>
<script type="text/javascript" src="assets/js/markdown.js"></script>
<script type="text/javascript" src="assets/js/prettify.js"></script>
<script type="text/javascript" src="assets/js/slides.js"></script>
<link href="assets/css/master.css" rel="stylesheet" type="text/css"></link>
<link href="assets/css/prettify.css" rel="stylesheet" type="text/css"></link>
<div class="window">
<div class="slider">
<div class="markdown title" title="Home">
##### And Other Principles of
##### Object Oriented Design
<div class="Paradigms" title="Paradigms 2">
<canvas id="paradigms" width="1200" height=900"></canvas>
<div class="markdown paradigm-summary" title="Principles">
# None Of These Principles
# Are Limited To OOP
##### They can be applied to any paradigm
<div class="markdown paradigm-summary" title="Principles 2">
# All Of These Principles
# Are For Production Code
##### They can be violated while developing
<div class="stupid Letters" title="STUPID">
<dd class="show">ingletons</dd>
<dd class="show">ight Coupling</dd>
<dd class="show">ntestable Code</dd>
<dd class="show">remature Optimization</dd>
<dd class="show">ndescriptive Naming</dd>
<dd class="show">uplication</dd>
<div class="solid Letters" title="SOLID">
<dd class="show">ingle Responsibility Principle</dd>
<dd class="show">pen/Closed Principle</dd>
<dd class="show">iskov Substitution Principle</dd>
<dd class="show">nterface Segregation Principle</dd>
<dd class="show">ependency Inversion Principle</dd>
<div class="markdown title" title="Leaky Abstractions Title">
# Leaky
# Abstractions
<div title="Camaro">
<img src="assets/images/camaro.jpg" class="full" />
<div title="Pedals">
<img src="assets/images/brake_pedal.jpg" class="full" />
<div class="markdown List" title="Leaky Abstractions">
## Leaky Abstractions
* They Are Everywhere
* Database Connections
* File-systems
* Floating Point Numbers
* Fixed-Size Integers (64 bit)
* They Are Impossible To Avoid
* All Abstractions Leak
* Leaks Are Technical Debt
* Fix Leakage When Found
* Maintain The Abstraction
* Capture Exceptions
* Check For Side-effects
<div class="markdown leak List" title="Leaky Abstractions 2">
## Leaky Abstractions (ctd)
* Leaky:
try {
} catch (DatabaseQueryException $e) {
/* Woah!
What Does The DB have to do
With Anything???
<div class="markdown leak List" title="Leaky Abstractions 3">
## Leaky Abstractions (ctd)
* Better:
try {
} catch (RecordNotFoundException $e) {
/* Eih!
A Person May Be A Record
But If It's A First-Class
Object, Why Leak The Record
<div class="markdown leak List" title="Leaky Abstractions 4">
## Leaky Abstractions (ctd)
* Better Still:
try {
} catch (PersonNotFoundException $e) {
/* I Get It!
The Person Wasn't Found!
It All Makes Sense!
<div class="markdown title" title="Law of Demeter Title">
# Law of
# Demeter
<div title="Strangers">
<img src="assets/images/strangers.jpg" class="full" />
<div class="markdown List" title="Law of Demeter">
## Law of Demeter
## Principle of Least Knowledge
* Know As Little As Possible
* Only Talk To Friends
* Objects Closely Related To The Class
* Reduces Dependencies
* Benefits:
* Maintainable Code
* Reusable Code
* Easy To Understand Code
<div class="markdown List" title="Complexity ">
## Complexity
* Abstraction Should Be Fractal
* Methods Abstract Operations
* Classes Abstract Responsibility
* Layers Abstract Functionality
* Packages Abstract Concepts
* Libraries Abstract Interactions
* Frameworks Abstract Communication
* By Maintaining The Abstraction
* We Can Focus On What
Rather Than How
<div class="Fractal" title="Fractal">
<canvas id="fractal" width="1000" height="1000" />
<div class="markdown List" title="Crosscutting Concerns">
## Crosscutting
* "Global" concerns
* Logging
* Authentication
* Caching
* Monitoring
* Fits Fractal Model!
<div class="markdown crosscut" title="Crosscutting Bad">
## Crosscutting
class User implements iUser {
public function login($u, $p) {
if (!is_valid($u, $p)) {
log("Password Invalid", $u);
return false;
log("Valid User", $u);
return true;
<div class="markdown crosscut2" title="Crosscut Decorator">
## Crosscutting Decorator
class UserDecorator implements iUser {
protected $user;
public function __construct(iUser $u) {
$this->user = $u;
public function login($u, $p) {
if ($this->user->login($u, $p)) {
log("Valid User", $u);
return true;
log("Password Invalid", $u);
return false;
<div class="markdown crosscut2" title="Crosscut Event">
## Crosscutting Events
function($data) {
log("Valid User", $data['user']);
function($data) {
log("Password Invalid", $data['user']);
<div class="markdown List" title="Tradeoffs">
## A Tradeoff
* What we lose in size
* More Classes
* More Code
* We gain in Flexibility
* Less "high level" code
* Code is "configuration"
* We gain in DRY
* Less Repitition
* Common Abstractions
* We gain in Readability
* Only focus on one layer
* Only With Clean abstractions
<div class="markdown List" title="Compare">
## Compare:
* 1 Class
* 2 Hashing Methods
* 2 Pseudo-Random Generators
* 6 Test Cases (6 assertions)
* Class Oriented Programming
* PHP-PasswordLib
* 38 Classes
* 4 Interfaces
* 12 Hashing Methods
* 1384 Test Cases (743 Unit Tests, 641 Vectors)
* 6 Pseudo-Random Generators
* Object Oriented Programming
<div class="markdown title" title="Real World Problems">
# Real World
# Applications
## (And Problems)
<div class="markdown List" title="Active Record">
## Active Record
* Business Objects Are "Active"
* Violates:
* Tight Coupling
* Single Responsibility Principle
* Open Closed Principle
* Interface Segregation Principle
* Dependency Inversion Principle
* Leaky Abstractions
<div class="markdown List" title="Active Record 2">
## Active Record (ctd)
* ORM Has The Same Problems
* Only If Applied To Business Objects
* Can Be Used In A Data Mapper
* (A Layer Between Business And Persistence)
<div class="markdown List" title="Service Locator">
## Service Locator
## Dependency Injection Container
## Global Registry
* A Container Is Injected
* Dependencies Are "Pulled" From Container
* Violates:
* Tight Coupling
* Single Responsibility Principle
* Dependency Inversion Principle
* Law Of Demeter
<div class="markdown List" title="Service Locator 2">
## Service Locator (ctd)
* Better Than Concrete Dependencies
* Adds A Place To Inject Mocks
* It Is Testable
* **NOT** Dependency Injection
* Depends On A Concrete Locator
* Class Is Not Dependent Upon An Abstraction
* Classes Dependencies Are Not Known
* Limits Reuse
* Can Make Edge Cases Harder To Test
<div class="markdown List" title="The New Operator">
## The `new` Operator
* Instantiating Classes Inside Objects
* Instead Of Injecting Dependencies
* Violates (Problems with):
* Tight Coupling
* Untestable Code
* Single Responsibility Principle
* Dependency Inversion Principle
* Static Coupling
<div title="A House">
<img src="assets/images/house.jpg" class="full" />
<div title="A Door">
<img src="assets/images/door.jpg" class="full" />
<div title="A Doorknob">
<img src="assets/images/doorknob.jpg" class="full" />
<div class="markdown title" title="Deep Inheritance">
# Deep
# Inheritance
<div title="Inheritance">
<img src="assets/images/inheritance.png" class="full" />
<div class="markdown List" title="Deep Inheritance 2">
# Deep Inheritance
* Adds Unnecessary Complexity
* Tightly Couples Trees
* A Form Of Static Coupling
* Favor Composition
Over Inheritance
* Relationships Between Classes:
* Always "Is A"
* Never "Acts As A"
* Never "Has A"
* Never "Can Be A"
<div class="markdown title" title="Deep Inheritance 3">
# Traits Are
# Inheritance!
##### Use Carefully!
<div class="markdown title" title="Good Enough">
# Good
# Is Not
# Good Enough
<div class="markdown title" title="Principles">
# These Are
# Principles
<div class="markdown title" title="Bend">
# You Can
# Bend Them
<div class="markdown title" title="Break">
# You Can
# Break Them
<div class="markdown title" title="Understand">
# But
# Understand
# Them
<div class="markdown title" title="Know What You're Giving Up">
# Know What
# You're
# Giving Up
<div class="markdown title" title="Why">
# And Understand
# Why You're
# Giving It Up
<div class="markdown title" title="EOD">
# At The End
# Of The Day
<div class="markdown title" title="Working">
# Working
# Is Better Than
# Perfect
<div class="markdown quote" title="Consistency">
## A Foolish Consistency
## Is The Hobgoblin
## Of Little Minds
##### Ralph Waldo Emerson
<div class="markdown List comments" title="Comments">
1. Questions?
3. Snide Remarks?
<div class="markdown credits" title="Credits">
## Anthony Ferrara
## @ircmaxell
<div class="pagination">