object oriented design in the - amazon...

72
@jessitron Object Oriented Design in the

Upload: others

Post on 03-Jun-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

@jessitron

Object Oriented Design in the

Page 2: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI
Page 3: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

6 package-level principles +

DRY YAGNI+&

SOLID

Page 4: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

classestypesJava

Haskell Ruby

ECMAScript

Page 5: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

?

Page 6: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Single Responsibility

Principle

SOLID

Page 7: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Don’tRepeatYourself

Page 8: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI
Page 9: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI
Page 10: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Sell

Track

Buy

Page 11: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

class Good implements InvItem, Purchase, Sellable{ InventoryImpl inventory; PurchaseImpl purchase; SellableImpl sellable; ... }

Java

Page 12: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Ruby

class Good include SellableItem include InventoryTracking include Purchaseend

Page 13: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Ruby

joy discipline

Page 14: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Haskell

joydiscipline

Page 15: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

data Good = Good SaleInfo InvInfo PurchInfo

instance ReceiptItem Good where format Good s _ _ = desc s + price s

Haskell

Page 16: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

dictionaries

functions

ECMAScript

Page 17: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

ECMAScript

var good = _.extend({}, invInfo, saleInfo, purInfo)

{ name: “Canteen”, sku: 37671287, price: 1399, format: function() {...} cost: 715}

Page 18: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI
Page 19: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

InterfaceSegregation

Principle

SOLID

Page 20: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

String receiptLine(Sellable item)

Java

Page 21: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

ECMAScript

function receiptLine(item) { console.log(“Cha-ching! profit ” + item.price - item.cost) return format(item.desc, item.price) }

Page 22: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI
Page 23: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Haskell

print :: ReceiptItem -> String

Page 24: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

LiskovSubstitution

Principle

SOLID

Page 25: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Java

List sneaky = new MyList()...

if (sneaky.length == -1) { System.out.println(“WAT!”)}

Page 26: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

LSP

Page 27: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

PLS

Page 28: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Principle of

Least

Surprise

Page 29: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Ruby

def form_receipt_line(item_sold) ... line_with_desc_and_priceend

Page 30: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

violate expectations

access global state

modify input

change the world

Page 31: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

DependencyInversionPrinciple

SOLID

Page 32: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

App

Hibernate

Page 33: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

App

HibernatePersistence

API

Page 34: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

HibernatePersistence APIAppfunction

another function

data

Page 35: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

ECMAScript

find items

format receipt

lineitem data

var items = _.map(codes, findItem)var lines = _.map(items, formatReceiptLine)

Page 36: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

> cat data.csv | grep 42 | cut -f2 | sort

ksh

Page 37: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Open/ClosedPrinciple

SOLID

Page 38: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Extension

Closed

Page 39: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

App

Module

LibraryClosed for

modification

Page 40: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

> cat data.csv | grep 42 | cut -f2 | sort

Page 41: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI
Page 42: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

package principles

3 x cohesion3 x coupling

Page 43: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

couplingcohesion

Page 44: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Common Reuse

Principle

Common ChangesPrinciple

Page 45: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Reuse-ReleaseEquivalency

Principle

Page 46: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

App

LibraryReuse This

Page 47: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

right problem

best solutionevidence of actual use

name and location

code reviews documentation

testsexisting functionality

maintenanceburden

machinery

bugslegacy code

Page 48: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Planning for reuse is premature

optimization

Page 49: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI
Page 50: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Premature optimizationis the root of all evil

Donald Knuth

Page 51: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

AcyclicDependencies

Principle

Page 52: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

App

Module

Library

Page 53: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

App

Module

Library

Module Module

Library LibraryLibraryLibrary

App

Page 54: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI
Page 55: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI
Page 56: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Stable Abstractions

Principle

Stable Dependency

Principle

Page 57: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Increasing stability

Page 58: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Concrete

Abstract

Page 59: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Reusable

You Are Here

Abstract

Page 60: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

DRY

Page 61: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

getTaxRate capitalize

customerRewards formatDate

Page 62: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

YouAin’tGonnaNeed It

Page 63: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

ConcreteYou Are Here Simple

Page 64: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

Time Reading

UseChange

Page 65: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI
Page 66: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI
Page 67: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

$ $$$

Page 68: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

6 package-level principles +

DRY YAGNI+&

SOLID

Page 69: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI
Page 70: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

SmallClear intent

older = better

Page 71: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

@jessitronFreedom

Page 72: Object Oriented Design in the - Amazon S3s3-eu-west-1.amazonaws.com/presentations2013/20_presentation.pdf · Object Oriented Design in the . 6 package-level principles + DRY YAGNI

@jessitron@jessitron