Show Menu

Object Oriented Design Cheat Sheet by david

A handy guide to the basic principles of Object Oriented Programming and Design. Covers standard and accepted principles, design patterns, and more! This is not intended to teach OOP, but as a reminder for those who already learned.

SOLID

Single Respon­sib­ility Principle
A class changes for only one reason
Op­en/­Closed Principle
A class should be open for extension, closed for editing
Li­skov's Substi­tution Principle
Derived types should cleanly and easily replace base types
In­terface Segreg­ation Principle
Favor multiple single­-pu­rpose interfaces over composite
De­pen­dency Inversion Principle
Concrete classes depend on abstra­ctions, not vice-versa

Other Principles

Don't Repeat Yourself (DRY)
Duplic­ation should be abstracted
Law of Demeter
Only talk to related classes
Hollywood Principle
"­Don't call us, we'll call you"
You Ain't Gonna Need It
Only code what you need now
Keep It Simple, Stupid
Favor clarity over cleverness
Convention Over Config­uration
Defaults cover 90% of uses
Encaps­ulation
What happens in Vegas...
Design By Contract
And then write tests
Avoid Fragile Base Class
Treat Base like a public API
Common Closure Principle
Classes that change together, stay together

Common Refactorings

Encaps­ulate Field
Generalize Type
Type-C­hecking ⇒ State/­Str­ategy
Condit­ional ⇒ Polymo­rphism
Extract Method
Extract Class
Move/R­ename Method or Field
Move to Superc­las­s/S­ubclass

http:/­/ma­rti­nfo­wle­r.c­om/­ref­act­ori­ng/­catalog

 

Class Associations: Association

Two objects have some sort of relati­onship to each other.
Exam­ple: Car uses Highway

Class Associations: Aggregation

An associ­ation where one object has-a (owns a) different object.
Exam­ple: Car has a Driver

Class Associations: Composition

An aggreg­ation with dependency - objects are mutually destro­yed­/cr­eated.
Exam­ple: Car has an Engine

Class Associations: Generalization

"­Is-­A" relati­onship (inher­ita­nce).
Exam­ple: Porsche is a Car

Class Associations: Realization

One class implements behavior that is abstractly defined in another class.
Exam­ple: An Animal may Move(), but a Duck would move by waddling

Class Associations: Dependency

One class weakly depends on another.
Exam­ple: Car uses Highway

 

Access Modifiers

PrivateOnly inside the same class instance
ProtectedInside same or derived class instances
PublicAll other classes linkin­g/r­efe­rencing the class
InternalOnly other classes in the same assembly
Protected InternalAll classes in same assembly, or derived classes in other assembly
StaticAccessible on the class itself (can combine with other accessors)

Design Patterns (GoF)

Abstract FactoryCreational
BuilderCreational
Factory MethodCreational
PrototypeCreational
SingletonCreational
AdapterStructural
BridgeStructural
CompositeStructural
DecoratorStructural
FacadeStructural
FlyweightStructural
ProxyStructural
Chain of Respon­sib­ilityBehavioral
CommandBehavioral
Interp­reterBehavioral
IteratorBehavioral
MediatorBehavioral
MementoBehavioral
ObserverBehavioral
StateBehavioral
StrategyBehavioral
Template MethodBehavioral
VisitorBehavioral
 

Share This Cheat Sheet!

Favourited by 24 Members:

dpnsw liyunzhen vbgenie oronm internaciulo Theosis Coldblackice Dranzz Epoc MrOggy85 webdevo and 14 more ...

Comments

Marc Marc, 11:29 6 Jun 12

thank you so much - this is perfect!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.