0% found this document useful (0 votes)
50 views

David - Object Oriented Design PDF

This document provides a cheat sheet on object oriented design principles and patterns. It lists the SOLID principles for single responsibility, open/closed, Liskov substitution, interface segregation and dependency inversion. Other principles covered include DRY, law of Demeter, Hollywood principle, YAGNI, KISS, and encapsulation. It also defines common class associations like generalization, realization, dependency, aggregation, composition and lists the common Gang of Four design patterns.

Uploaded by

kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

David - Object Oriented Design PDF

This document provides a cheat sheet on object oriented design principles and patterns. It lists the SOLID principles for single responsibility, open/closed, Liskov substitution, interface segregation and dependency inversion. Other principles covered include DRY, law of Demeter, Hollywood principle, YAGNI, KISS, and encapsulation. It also defines common class associations like generalization, realization, dependency, aggregation, composition and lists the common Gang of Four design patterns.

Uploaded by

kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Object Oriented Design Cheat Sheet

by David Harris (david) via cheatography.com/387/cs/179/

SOLID Other Principles (cont) Class Associ​ations: Genera​liz​ation

Single Respon​sib​ility Principle Design By Contract

A class changes for only one reason And then write tests

Op​en/​Closed Principle Avoid Fragile Base Class


"​Is-​A" relati​onship (inher​ita​nce).
A class should be open for extension, closed Treat Base like a public API
Exam​ple: Porsche is a Car
for editing
Common Closure Principle
Li​skov's Substi​tution Principle Classes that change together, stay together Class Associ​ations: Realiz​ation

Derived types should cleanly and easily


replace base types Common Refact​orings

In​terface Segreg​ation Principle Encaps​ulate Field

Favor multiple single​-pu​rpose interfaces Generalize Type One class implements behavior that is
over composite abstractly defined in another class.
Type-C​hecking ⇒ State/​Str​ategy
Exam​ple: An Animal may Move(), but a Duck
De​pen​dency Inversion Principle Condit​ional ⇒ Polymo​rphism
would move by waddling
Concrete classes depend on abstra​ctions, Extract Method
not vice-versa
Extract Class Class Associ​ations: Dependency

Move/R​ename Method or Field


Other Principles
Move to Superc​las​s/S​ubclass
Don't Repeat Yourself (DRY)
http:/​/ma​rti​nfo​wle​r.c​om/​ref​act​ori​ng/​catalog
Duplic​ation should be abstracted One class weakly depends on another.
Exam​ple: Car uses Highway
Law of Demeter Class Associ​ations: Associ​ation

Only talk to related classes


Access Modifiers
Hollywood Principle
Private Only inside the same class
"​Don't call us, we'll call you"
instance
Two objects have some sort of relati​onship to
You Ain't Gonna Need It Protected Inside same or derived class
each other.
Only code what you need now Exam​ple: Car uses Highway instances

Keep It Simple, Stupid Public All other classes

Class Associ​ations: Aggreg​ation linkin​g/r​efe​rencing the class


Favor clarity over cleverness
Internal Only other classes in the same
Convention Over Config​uration
assembly
Defaults cover 90% of uses
Protected All classes in same assembly, or
Encaps​ulation Internal derived classes in other assembly
An associ​ation where one object has-a (owns
What happens in Vegas... a) different object. Static Accessible on the class itself (can

Exam​ple: Car has a Driver combine with other accessors)

Class Associ​ations: Compos​ition

An aggreg​ation with dependency - objects are


mutually destro​yed​/cr​eated.
Exam​ple: Car has an Engine

By David Harris (david) Published 9th January, 2012. Sponsored by CrosswordCheats.com


cheatography.com/david/ Last updated 5th June, 2014. Learn to solve cryptic crosswords!
Page 1 of 2. http://crosswordcheats.com
Object Oriented Design Cheat Sheet
by David Harris (david) via cheatography.com/387/cs/179/

Design Patterns (GoF)

Abstract Factory Creational

Builder Creational

Factory Method Creational

Prototype Creational

Singleton Creational

Adapter Structural

Bridge Structural

Composite Structural

Decorator Structural

Facade Structural

Flyweight Structural

Proxy Structural

Chain of Respon​sib​ility Behavioral

Command Behavioral

Interp​reter Behavioral

Iterator Behavioral

Mediator Behavioral

Memento Behavioral

Observer Behavioral

State Behavioral

Strategy Behavioral

Template Method Behavioral

Visitor Behavioral

By David Harris (david) Published 9th January, 2012. Sponsored by CrosswordCheats.com


cheatography.com/david/ Last updated 5th June, 2014. Learn to solve cryptic crosswords!
Page 2 of 2. http://crosswordcheats.com

You might also like