Show Menu

Object-Oriented Design Principles Cheat Sheet by

Design principles mostly taken from Head First Object-Oriented Analysis & Design
development     programming     oop     software     object-oriented

Basic Principles

Encaps­ulate what varies.
Code to an interface rather than to an implem­ent­ation.
Each class in your applic­ation should have only one reason to change.
Classes are about behavior and functi­ona­lity.

Basic OO Terms

Abstra­ction
The process of separating ideas from specific instances of those ideas at work.
Polymo­rphism
The provision of a single interface to entities of different types. Subtyping.
Inheri­tance
When an object or class is based on another object or class, using the same implem­ent­ation; it is a mechanism for code reuse. The relati­onships of objects or classes through inheri­tance give rise to a hierarchy.
Encaps­ulation
Enclosing objects in a common interface in a way that makes them interc­han­geable, and guards their states from invalid changes

Favor the following over inheri­tance

Delegation
When you hand over the respon­sib­ility for a particular task to another class or method.
Compos­ition
Use behavior from a family of other classes, and change that behavior at runtime.
Aggreg­ation
When one class is used as part of another class, but still exists outside of that other class.
 

Don't Repeat Yourself (DRY)

Avoid duplicate code by abstra­cting out things that are common and placing those things in a single location.

DRY is about having each piece of inform­ation and behavior in your system in a single, sensible place.

Single Respon­sib­ility Principle

Every object in your system should have a single respon­sib­ility, and all the object's services should be focused on carrying out that single respon­sib­ility.

Open-C­losed Principle

Classes should be open for extension, and closed for modifi­cation.

Liskov Substi­tution Principle (LSP)

Subtypes must be substi­tutable for their base types.

Interface Segreg­ation Principle (ISP)

Clients should not be forced to depend upon interfaces that they don't use.

Dependency Inversion Principle (DIP)

a. High level modules should not depend upon low level modules. Both should depend upon abstra­ctions.

b. Abstra­ctions should not depend upon details. Details should depend upon abstra­ctions.
 

References

Wood, David, Bert Bates, Kathy Sierra, Brett D. McLaug­hlin, Gary Pollice, and David West. Head First Object­-Or­iented Analysis and Design: A Brain Friendly Guide to Object Oriented Progra­mming. Cambridge: O'Reilly Media, Incorp­orated, 2006. Print.

"­Abs­tra­ction (computer Scienc­e)."­ Wikipedia. Wikimedia Founda­tion, 18 Apr. 2014. Web. 25 Apr. 2014. <http:/­/en.wi­kip­edi­a.o­rg/­wik­i/A­bst­rac­tio­n_(­com­put­er_­sci­ence)>

"­Pol­ymo­rphism (computer Scienc­e)."­ Wikipedia. Wikimedia Founda­tion, 25 Apr. 2014. Web. 25 Apr. 2014. <http:/­/en.wi­kip­edi­a.o­rg/­wik­i/P­oly­mor­phi­sm_­(co­mpu­ter­_sc­ience)>

"­Inh­eri­tance (objec­t-o­riented Progra­mmi­ng)." Wikipedia. Wikimedia Founda­tion, 21 Apr. 2014. Web. 25 Apr. 2014. <http:/­/en.wi­kip­edi­a.o­rg/­wik­i/I­nhe­rit­anc­e_(­obj­ect­-or­ien­ted­_pr­ogr­amming)>.

"­Enc­aps­ulation (objec­t-o­riented Progra­mmi­ng)." Wikipedia. Wikimedia Founda­tion, 21 Apr. 2014. Web. 25 Apr. 2014. <http:/­/en.wi­kip­edi­a.o­rg/­wik­i/E­nca­psu­lat­ion­_(o­bje­ct-­ori­ent­ed_­pro­gra­mming)>

Download the Object-Oriented Design Principles Cheat Sheet

1 Page
//media.cheatography.com/storage/thumb/scottashipp_object-oriented-design-principles.750.jpg

PDF (recommended)

Alternative Downloads

Share This Cheat Sheet!

 

Comments

DaveChild DaveChild, 17:58 27 Apr 14

Great cheat sheet!

Scott Shipp Scott Shipp, 12:08 6 May 14

Thanks for the comment! Glad someone finds it useful!

Muhammad Muhammad, 10:28 18 Jul 14

Thanks! It really helps.

Thomas Thomas, 13:52 17 Nov 14

Encapsulation at its finest :D

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Regular Expressions Cheat Sheet
          Object Oriented Design Cheat Sheet