Object-Oriented Design Principles Cheat Sheet

A Programming › OOP cheat sheet in English by scottashipp

Design principles mostly taken from Head First Object-Oriented Analysis & Design

95,229 views 18,779 downloads 22 Apr 2014 History
5.0 avg · 8 ratings

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. <ht­tp:­//e­n.w­iki­ped­ia.o­rg­/wi­ki/­Abs­tra­cti­on_­(co­mpu­ter­_sc­ien­ce)>

"­Pol­ymo­rphism (computer Scienc­e)."­ Wikipedia. Wikimedia Founda­tion, 25 Apr. 2014. Web. 25 Apr. 2014. <ht­tp:­//e­n.w­iki­ped­ia.o­rg­/wi­ki/­Pol­ymo­rph­ism­_(c­omp­ute­r_s­cie­nce­)>

"­Inh­eri­tance (objec­t-o­riented Progra­mmi­ng)." Wikipedia. Wikimedia Founda­tion, 21 Apr. 2014. Web. 25 Apr. 2014. <ht­tp:­//e­n.w­iki­ped­ia.o­rg­/wi­ki/­Inh­eri­tan­ce_­(ob­jec­t-o­rie­nte­d_p­rog­ram­min­g)>.

"­Enc­aps­ulation (objec­t-o­riented Progra­mmi­ng)." Wikipedia. Wikimedia Founda­tion, 21 Apr. 2014. Web. 25 Apr. 2014. <ht­tp:­//e­n.w­iki­ped­ia.o­rg­/wi­ki/­Enc­aps­ula­tio­n_(­obj­ect­-or­ien­ted­_pr­ogr­amm­ing­)>

Badges

Useful Cheat Sheet Great Cheat Sheet Nice Cheat Sheet Good Cheat Sheet Appreciated Cheat Sheet Downloaded from Unusual Locations × 14 🇧🇾 Big in Belarus

Comments (4)

Thomas 13:52 17 Nov 2014

Encapsulation at its finest :D

Reply
Muhammad 10:28 18 Jul 2014

Thanks! It really helps.

Reply
Scott Shipp 12:08 6 May 2014

Thanks for the comment! Glad someone finds it useful!

Reply
DaveChild 17:58 27 Apr 2014

Great cheat sheet!

Reply

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.