New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

Software Engineering

by: Nick Rowe

Software Engineering CS 51000

Nick Rowe
GPA 3.68


Almost Ready


These notes were just uploaded, and will be ready to view shortly.

Purchase these notes here, or revisit this page.

Either way, we'll remind you when they're ready :)

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

Class Notes
25 ?




Popular in Course

Popular in ComputerScienence

This 21 page Class Notes was uploaded by Nick Rowe on Saturday September 19, 2015. The Class Notes belongs to CS 51000 at Purdue University taught by Staff in Fall. Since its upload, it has received 22 views. For similar materials see /class/208098/cs-51000-purdue-university in ComputerScienence at Purdue University.

Similar to CS 51000 at Purdue

Popular in ComputerScienence


Reviews for Software Engineering


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 09/19/15
RefacToring o MarTin Fowler and KenT Beck John BranT William Opdyke Don RoberTs Refadormg Improving The Design of ExisTng Code Addison Wesley 1999 I nefacturinu noun a change made To The inTerna sTrucTLre of sofTware To make iT easier To undersTand and cheaper To modify wiThouT changing iTs observable behavior a factor verb To resTrucTure sofTware by applying a series of refacTorings February 14 2005 RefacToring Movie 0 Class diagram of The sTarTing poinT classes February 14 2005 a STraighT from The book The movie February 14 2005 RefacToring applied a program To calculaTe and prinT a sTaTemenT of a cusTomer39s charges aT a video sTorequot price depends on how long The movie is renTed and The caTegory of also compLITe frequenT renTer poinTs RefacTor39ing Movie Class public class Mcvie lt public static final int CHILDREN239 public static final int REGULARS039 public static final int uEwRELEAsE1 39 private string title private int pricecade public Moviestring title int pricecode tit1etit1e pricecade pricecade public int getPriceCodeO u C 39 ret rn price ode February 14 2005 public void setPriceCodeiint arg l iprjcecode aiq 1 public String qet39l itleO i return it itle Refactoring Rental Class public class Rental private Movie 7 vie private int 7daysRented public RentalMovie movie int daysRented movie 7movie 7daysRented daysRented public int getnaysRentedo return 7daysRented l public Movie getMovieo return 7mo i I l February 14 2005 Refactoring Customer Class public class customer public string statemento double totalAmount int frequentRenterPoints o Enumeration rentals rentalelements string result Rental Record for r getllame0 n while rentalshasMoreE1ements double thisAmoun 0 Rental each Rental rentalsnextElement determine amounts for each line switch eachgetMoviegetPriceCodeO case Movie REGULAR thisAmount 2 if eachgetnaysRented thisAmount each getDaysRented 2 break February 14 2005 Refactoring39 Customer Class public class Customer 4 private string 7 ame private Vector 7rentals new Vectoro public Customerstring name I 7 ame name l public void addRentalRental arg rentals addElement arg public string getuameo l return n m l February 14 2005 Refactoring Customer Class public class customer public string statemento case MWie EWRELEASE isAmount eachgetDaysRented 3 break case MWieCHILDRElIS 39 mount 15 if eachgetnaysRented thisAmounteachgetnaysRented 3 break add frequent renter points frequentRenterPoints add bonus for a two day new release rental if each getucvie getPricecodeO MovienEwRELEAsE 55 gt 1 39 February 14 2005 Refactor39ing Customer Class public class Customer public String statementn show fiqlues for this rental result tquot v eachgetMoviegetTitle04 t v Stringvalue0fthismount an totalmnount thismnounl add footer lines resu t quotmount owed is Stinqvalue0ftotalmnount3 v result e You earned Stillgvalue0ffrequentRenterPoints frequent renter pointsn 39 return result February 14 2005 Refactoring problem statement Add a htmlstatment method which returns a customer statement string containing html tags and there will be some changes to the way movies are classified affecting frequent renter points and charging February 14 2005 Refactoring 0 Interaction diagram for the statement method fnr all rentals 5 l 5 gethe gEIPliCEOdE getDaysHanteuloi i February 14 2005 Refactoring step 1 I Write a test suite 0 Refactoring should not affect the outcome of tests The test suite must exercise the published interface of the classes 0 Obviously refactoring should not affect the published interface 50 avoid publishing interfaces too early February 14 2005 Refac l39or39ing step 2 o statemento IS overly long apply The Exfracf Mefhod refac rormg public Slxinq summary 1 n e nmmm n i mannmwmmm n xalinn rentals 2 xenlalelemzntSH Rental 11 Slxinq 195 t m m qeulmz n while 1xnlalshas nte lemznls1 D l dnuhle mama n Rental each mm xenlalsJuextElemzntH l deteunine mum in each line switch 1eachqetnnviznyeu xicecndenb case n lrum smumun 4 2 if teasinqelbayskentzd gt 2 thismnnuan1eachqeuayskenled1172 15 Inesk case nuvimum nuansa lhismnmu t lt eachquayskentedn a 3 bleak case aniecnILDREus lhisnlnmlnl lt 15 if teasinqetbayskenled gt 3 lhismnnuaneachqeuayskenled173 15 husk February 14 2005 Refac l39or39ing step 2 public int amounti orRenta1 each int thisAlnount 0 switch eachgetMoviegetPriceCodeO case MovieREGULAR thisAmount 2 if eachgetDaysRented gt 2 thisAmounteachgetnayskented 2 15 case MovieuEwRELEASE mount eachgetDaysRented 3 break case MovieCIIILDREIIS thisAmunt 15 if eachgetDaysRented gt 3 15 thisAllwunt each getDaysRented 3 break return thisAmount February 14 2005 publin suing statement 1 am e m w L Juan n z Rental Recnxd m y r Rental gm each yelbayskentedl gt totalnlnnunt 2 msnmm ll add fnntex lines zesult mnnunl wed is st gained Stinqvalue flftequenulenlexl ninl 4 Eleq 39 xzunn result February 14 2005 0 TEST February 14 2005 n zlemenl n s 0 a m day new if 1teanhqetnnvietLyeLPxinecndeH mm u mun g w eachyeu nvie u gn su 39 n9 value f ummmunn 39 c inqvallle f1ln Lamnnllnll n Refac toring step 2 D qeulamzH n mentalb rentals nexlElemllIN t umnm alnnunlEnIJeachH x int releasz xental minaumsams 1 frequenlkenlexPnints Title1h v39 v nquot xesult Ynll um xenlet pnmtsn Refac toring step 3 Refac l39or39ing step 4 o oops double gt int bug public double amountF0rRental each I double thismnount 0 switch each getuovieo getPriceCode L case mvie use hismnou t 2 if eachqetDaysRented gt 2 thismnounteecngetnaysaentedoez 15 break case MovieNEW7RELEBSE thismnount eachgetDaysRented 3 t 15 if eachqetDaysRented gt thismnounteacngetnaysaentedoea 15 I return thismnount February 14 2005 17 Refac l39or39ing step 5 public double amunti orRental aRental double result 0 switch aRentalgetMcviegetPricecodeo case MovieREGULAR result 2 if aRenta1getDaysRented 2 aRenta1getDaysRentedOZ 15 result case Movie uEwRELEAsE u t aRenta1getDaysRented 3 break case MovieCIIILDREIIS result 15 if aRenta1getDaysRented result aRentalgetDaysRentedOS 15 break return result February 14 2005 19 Refac toring step 5 0 Variable names no r helpful public double amountFOI Rental each 1 doub thisBmount 0 suit ch each getuovieo getPriceCode y case MovieREGlJL thismnount 2 if eachgetDaysRented gt 2 thismnounteachgetDaysRentedorz it 15 break case Movie um umnsa hismnount 7 eachgetDaysRented 3 reek thismnount 1 if eachqetDaysRented thisnmountlteacugetnaysxentedoea 1 5 break return thismnount February 14 2005 18 Refac toring step 6 0 Moving amoun r compu ra r ion does not use info from Cusfomer only Rental class CusLomer public double amountForRental aRental ouble esult 0 switch aRentalJetMovieOqetPriceC odeO l a vieREGllLBR result 2 if aRentalgetDaysRented gt 2 result aaentalgetuaysxentemyz t 15 break case Movie swimmnss result aRentalqetDaysRented 3 result 15 if aRentalgetDaysRented gt 3 4agentalgetuaysxentedoea 15 return result February 14 2005 20 class R public dou switch qetMovie Refactor39ing step 6 ental double getc harqeo 1e re ult 39 o getPriceCode e Movie um result 2 if getDaysRentedO result qetDaysRented72 15 brea case MovieNEW7RELEBS res t getDaysRentedO 3 15 if getDaysRented result break 4 getDaysRented 73 It 1 5 return result February 14 2005 Refactor39ing39 step 7 class Customer public Stxinq statenentu double tat aunt int rre entkentexl nlnls Enumexallnn e tal e ixenlal elements string 7 rent 1 Renali fax getuanen quotn I 7 mental rentalsnexmlenentn trar eaem eanmun 1 a d f reguenuzente Pu aga hnmls a mu day an release xental if leach get ia1 getrrieecuueu nvieJlmLmLEnSEML n rreguentuenterlmintsH eaen getnaysrenteun Ishnw figures fax this zental ul L eaengetuuvieu getwitlen L haunt s n 39 ll add funter lines lesult mnmml owed is Slinyvalue 1lnlalknnu0 t n xzsull quotYou earned Stinqvalnz ft lepunmentexl nintsD teeguent rental pninlsn return result l February 14 2005 Class Customer public double amuntF0rRenta1 aRental return aRenta1getCharge Refactoring step 6 February 14 2005 Refactoring39 step 7 class customer public string statement dnuhle tatallanmunt Int fxequznllenlexPnl t e u a uineratian re als e ixenlalelemenls1b Rental eeuru fnx getuanen n string result while 1rentalsnasnurezlenentsn 39 t n uhle tn nun ental e c mentalp rentalsnextalenentm thisnnuun e eaen getcnar 2H ints ll ad freguentn ad hon fax a mu day new release rental etrrieecuuan anieJlmillELEASEms if leachqetnnvieH g eaengetnaysnenteun gt it fxeqnzntkentexyn39ntst gures fur tn39s rental eaengetnuuie n getwi stringualuenr1tnisnnamtp tnisnnmunt Ilshtm i resul tlen tquot nquot tutallunuunt ll add miter lines result mmunl wad is Slimqvalne f1lnlalmmmu n 39 xesult e You earneu Slinyvalllenf1f egue 1 ent r ntnenteryuints egu r ter 039 n intsn return result February 14 2005 Refactoring a State of classes offer moving The charge me rhod amountFor has been deleted February 14 2005 Refac l oring step 9 O Exfr acf Me lod frequer renfer communion c1333 Customer 331133 53333 333333 333313 33331133333 3 n 33 f3333333333333333 3 n 33 3333 33 313 3 7 3113333313 3 3333 u 3 333333 3 3vr 33 1 333333 33 313333313 l 3 3331 33331333xm133331gt 3333 53333 33331 3 33313 333313333333 33 31 333 333 3333333 3333 9 3313333 33331 1 f33333333333333333 333 33331 3 3333333333 33 13n3 3 5333333133331333333c333333py 3 3quot 331133333 3 333333c33333n II 333 3333 13333 33331 3 33 3333 33 1 33333331333u331n3333y 3 quot3n 33331 33 333 3533333133nrz3333333333333333 3 3333 33333 333333 333333 33333 33331 February 14 2005 Refac toring step 8 0 Replace Temp wufh Query fhisAmaunf is redundant class CuSL 33333 33333 3333333 3333 3331333 3 3 33333333333333333 3 3 33 39 3333 3 3 73 3 3133333un 33333 3333 3 33331 333333 333 3 3333333 4 while xenlalsJ aanzeElemenlSUI I ll nt 3 h Rental rtntalsnext 1unznl 3 33 3 3 31 3 333 333333 3333 333 3333 33 3 33 day 333 3313333 33331 3 1133333333333133333333c333 p 333332373332353 33 33333333333n gt 1 t33333333333333333 393 33331 33 w 3 3333333333 33r313u3 3 333333133331333333c333331pp 3 3 331133333 33 33333303 3 n ll add 3333 13333 33331 33 33333 W33 33 1 35333331333 33133333 3 3n 33331 33 1333 333333 3533333133333333333333333333y 3 n 3333 33333 333333 33333 33331 February 14 2005 Refac toring step 9 class Customer 331133 33333 333333 33313 33113333 n 3333333 3 n t ls xenLalJlementsH 3 3 33333313 3 3quot 33 333333333 3 3333333 333 3 53333 33331 133331 333333 3 33313 13333133333333u3333sm 33331 3 3331 33331333331333311t h H f3333333333y333 3lt 333 33333333n3333y33331p 3 E 13333 333333 333 333 33331 31 33 wquot 3 33333333333 33131303 v39 33331333 1333333c333331pp 3 u3 5 33313333 33 3333330333 II 333 33333 13333 1 3333 33 3s33331333n3311u3333 3 3w 33331 33 333 f3333333333333333 3333mm 33331 33 333333 333333 3533333133nr1 3 33333 33333 33331 February 14 2005 Refac tor39ing step 9 class Rental public int geti requentkenterPoints if getMovieo getPriceCode0 MovienEwRELEAsE amp getDaysRentedO gt 1 return 2 else return 1 February 14 2005 29 Refactoring 0 Interaction diagram February 14 1 Refacforing a Class diagram before extraction and movement offhe frequent mm po n5 calculation me 1 1 I Rama 1 Cusmmer l priceCade int daysRermed Int 1 stalem em February W JM W o T J fom J t L H r 39mrauremamo gamma geIPnc OudeU D gaDaysRentego Refac toring step 10 0 Replace Temp wifh Query on kmpom cs make on mdhod complex a fore a on upllen class Customer 5 int slaementH L E m 2 u 5 5 I i g E E al21anencs1 String esull en 1 n nxli fnx Y get alnLH Y snuummumsm while xentalst enlal each UlenLalCI m Ilshww figures in um lent mum v w eunugnnu 15 nexlElunzn mm H Liinqvaluenfleachqelchaxqeu7 5 Intalnlnnunl eachajetchanje ll add fnntex 1a xesult e Alnnunt wed is u eunell Stinyvaluenftflelplentkentru nintsb quent quotum pointsh um resull February 14 2005 all vieibqt1il1e1b l uh s mvaluunfuummuuump n 39 la frequentllentexPnints olt each u Ezequentnentexl ninlsly39 xesull t um Refacfor39ing step 10 class customer public string statemento int frequentRenterPoints o Enumeration rentals rentalelements string result Rental Record for getllameO while rentalshasMoreElementso Rental each nn Rental rentalsnextE1ement P gt a I1 show figures for this rental result t eachgetMovieget l itle tquot stringvalueofeachgetcharge n add footer lines result Amount owed is quotStingva1ueofget l otalchargeO n result You ear ed Stingva1ue0f frequentRenterPoints frequent renter pointsn return result February 14 2005 Refacfor39ing step 11 0 Replace Temp wifh Query class Customer public string statemento int frequentRenteIPoints 0 Enumeration rentals 7 ntalelements string result Rental Record for getuameo n while rent als hasMoreE lements 0 Rental each en R a1 rent als nextElement show figures for this rental result t eachqetMovieqetTit1e t Stringvalueofeachgetcharge u add footer lines result H o t owed result t You earned StinqvalueoffrequentRenterPoin s frequent renter pointsn return result is Stinqvalue0fgetTotalChargeJ n t February 14 2005 Refacforing step 10 class customer private double getrotalchargeo double result o Enumeration rentals rentalselements while rentalshasuorerlementso Rental each Rental rentalsnextElement result eachgetcharge return result February 14 2005 Refacforing step 11 0 Replace Temp with Query class Customer public string statemento Enumeration rentals rentalelements string result Rental Record for u getllame0 n while rentalshasMoreElementsO Rental each ntal rentalsnextE1ement show figures for this rental result tquot eachgetMovie get l itle tquot stringvalueofeachgetcharge n add footer lines result Amount owed is Stingvalueofget l otalchargeO n result frequent renter pointsn return result February 14 2005 You earned Stingva1ue0fgeti requentkenterPoints RefacToring sTep 11 class customer private double getFrequentRenterPoints double result o Enumeration rentals rentalselements while rentalshasMoreElementso Rental each Rental rentalsnextElement result eachgetFrequentRenterPoints return re sult February 14 2005 RefacToring 0 Class diagram after extraction oftluz totals 0 Interaction diagram February 14 2 RefacToring a Class diagram before 9 Interaction diagram February 14 1 RefacToring 9 Remarks I MosT refacToring redLIce code size bLIT This is noT necessarily The case The poinT is To make code easier To modify and more readable a Performance geTs a hiT by running The same loop Three Times or does iT Profile The program and find The answer February 14 2005 Software extension 0 The requested New functionality duplication methOd can be added w39 mm39mal cade 0 Getting ready to change the classification of the movies in the store 0 Perhaps new classification perhaps modification to existing class customer 0 Charging and frequent renting will be affected public string htmlstntement Enumeration rentals rentalelement5 39 tr39 result ltH1gtRental Record forltEMgt v getllameo ltEZMgtltH1gtltPgtn whjle rent 31 hasMoreElement S 0 l a ental euch E n w rent getMovieqetTitle H n rlngvalue0feachqetcharge ltERgtn add footer li resul gt ltEgtBmount owed isltErD Stingvalue0fgetTotalCharge ltErpltvgtnquot re ult H rn ltEbD Stingvalue0fqetFrequentRenterPoints ltEMgt fr return result equent renter pointsltPgtn February 14 2005 February 14 2005 Refactoring step 12 Refactoring step 12 0 Move getCharge class Ren o Replacing conditional logic on Price Code with polymorphism Lal H public double getCharge 1 double ll 1 suite getuovieqetgrieeCOdey a ieREGULBR result 2 if qetDaysRented gt 2 result qetDaysRented72 15 break case Movie usw ammss r 1L getDaysRentedK 3 eat case bbvleCHILDRENS esult if getDaysRented result qetDaysRented73 15 return result February 14 2005 February 14 2005 Refac foring step 12 class Movie public double getcnarqeint daysRented doub result o SW1 c qetPriceCode case REGULAR result a 2 if getDaysRented gt 2 result qetDaysRented72 15 break getDaysRentedO it 3 if getDaysRentedO gt 3 result ltqetDaysRented73 it 15 break return result February 14 2005 45 Refac foring step 13 a Move gefFrequenfRen ferPoinst class Rental public int geti requentkenterPoints if getMovie getPriceCode ampamp getDaysRented gt D n 2 Movie lleRELEAsE e1 Se return 1 February 14 2005 47 Refac foring step 12 class Rental public double getcnar e 4 urn imovieqetCharge7daysRented February 14 2005 Refac foring step 13 class Movie public int getFrequentRenterPointsint daysRented if getPriceCodeO MavienEwRELEAsE 55 daysRented gt D return 2 e1 se return 1 Class Rental public int geti requentRenterPoints return movie geti requentRenterPo ints daysRented February 14 2005 Refacforing o Inheritance MEME getChangeo 7 ReguiarMmie I i ChlldrenMwe I NewReleasenme I i I 1 I i I l i i February 14 2005 49 Refacforing a Class diagram before moving methods To movie 0 Class diagram afTer moving methods To movie February 14 2005 51 Refacforing I Inheritance Childrenan QETQWQEO NewWei aasePnce germamao aacwargeo return pricegetcharge February 14 2005 50 Refacforing step 14 0 Replace Type Code wi l SfafeSfrafegy class Movie public Moviestring name int priceCode me a Jricecode pricecode February 14 2005 52 Refactoring step 14 Class Movie public Movieltstring name int pricecade me setPricecadeltpricecade February 14 2005 Refactoring step 15 Class Movie public int getPriceCodeo return pricecode gublic void setPriceCodeint arg pricecade arg private int pricecade February 14 2005 Refactoring step 14 abstract class Price abstract int getPricecadeo class childrenPrice extends Price int getPricecode H eturn MOVIECHILDREII class HewReleasePrice extends Price i t getPricecode return MOVIE EWRELEASE class RegularPrice extends Price int getPricecode H return MOVIEREGULAR February 14 2005 Refactoring step 15 class Movie public int qetlzriceCOdeo ret r 39 price qetPriceCode public void setPriceCodeint arg L switch arq new RegularEriCeU new childrenyriceo new NewReleasePriCeO default throw new IllegalnrgumentException Incorrect Price Code private Price iprice February 14 2005 56 Refac foring step 16 0 Move Me lod class Movie public double getchargeint daysRented L d uble re 1t 0 switch geLPriceCodeD case curm esult 2 if qetnaysRentedO gt 2 result qetDaysRented72 it l5 result qetDaysRentedO e 3 ult 15 if qetnaysRented result qetDaysRented73 it l5 In return result February 14 2005 57 Refacforing39 step 16 0 Replace Condifional wifh Polymorphism class Price double getchargeint daysRented I double res It i U39 u r switch getFriceCode case MOVIEREGULBR resu if getDaysRentedO gt 2 re u t ltqetDaysRented72 it 15 brea case MovIEMEwiRELEASE result getDaysRentedO it 3 resu 5 if qetDaysRentedO gt 3 result qetDaysRented73 it 15 break return result Febmary 14 2005 59 Refactoring step 16 class Movie public double getchargeint daysRented return pricegetcharge daysRented February 14 2005 58 Refacfor ing39 step 16 ass Regularlzrice double getchargeint daysRented l 2 if ge DaysRentedO result qetDaysRented72 it 15 double re return result 1 class NewReleasePrice double getChargeint daysRented return daysRented it 3 class childrenprice double getchargeunt daysRented o hle result 15 if getDaysRentedO result qetDaysRented73 439 15 return result class Price abstract double getchargeunt daysRented February 14 2005 60 RefacToring sTep 17 0 Replace Condifional wiTh Polymorphism class Rental int getrrequentkenterPointsint daysRented 39f getPriceCodeO MWiellEWRELEASE as daysRented gt 1 return 2 else return 1 February 14 2005 RefacToring Principles 0 Why do we rsfacTor 0 To improve The design of sofTware 0 To make sofTware easier To undersTand 0 To help you find bugs a To make you program fasTer 0 When should we refucTor 1 RefacTor when you add funcTionaliTy 2 RefacTor when you need To fix a bug 3 RefacTor as you do code reviews Refacfor39 when The code sfar39fs fo smell a WhaT abouT performance 0 Worry abouT performance only when you have idenTified a performance problem February 14 2005 RefacToring sTep 17 class Movie int getrrequentkenterPointsint daysRented return pricegetFrequentRenterPointsdaysRented class Price int getFrequentRenterPoinT Sint daysRented retur class NewReleasePrice int getrrequentkenterPointsint daysRented l urn daysRented gt 1 February 14 2005 Bad Smells in Code If 11 sTnks change 11 quotGrandma Back on child rearing DuplicaTed Code sTench 10 If The same code sTrucTure is repeaTed I ExTracT MeThod gaTher duplicaTed code I Pull Up Field move To a common parenT I Form TemplaTe MeThod gaTher similar parTs leaving holes I SubsTiTuTe AlgoriThm choose The clearer algoriThm I ExTracT class for unrelaTed classes creaTe a new class wiTh funcTionaliTy February 14 2005 Bad Smells in Code Bad Smells in Code Long MeThod sTench 7 Large Class sTench 7 If The body of a meThod is over a page choose your page size If a class has eiTher Too many variables or Too many meThods I ExTracT MeThod exTracT relaTed behavior I ExTracT Class To bundle variablesmeThods I Replace Temp wiTh Query remove Temporaries when They obscure meaning InTroduce ParameTer ObjecT slim down parameTer lisTs by making Them inTo objecTs Replace MeThod WITh MeThod ObjecT sTill Too many parameTers Decompose CondiTionals condiTional and loops can be moved To Their own meThods February 14 2005 65 February 14 2005 Bad Smells in Code Bad Smells in Code Long ParameTer LisT sTench 6 DivergenT Change sTench 5 A meThod does noT need many parameTer only enough To be If you find yourself repeaTedly changing The same class Then able To reTrieve whaT iT needs There is probably someThing wrong wiTh iT I Replace ParameTer wiTh MeThod Turn a parameTer inTo a message I ExTracT Class group funcTionaliTy commonly changed inTo a class I InTroduce ParameTer ObjeCT Turn several parameTers inTo an objecT February 14 2005 67 February 14 2005 Bad Smells in Code Shngun Surgery sTench 5 If you find yourself making a loT of small changes for each desired change 0 Move MeThodField pull all The changes inTo a single class I Inline Class group a bunch of behaviors TogeTher February 14 2005 DaTa Clumps Bad Smells in Code sTench 4 DaTa iTems ThaT are frequenle TogeTher in meThod signaTures and classes belong To a class of Their own 0 ExTracT Class Turn relaTed fields inTo a class I InTroduce ParameTer Objecl39 for meThod signaTures February 14 2005 Bad Smells in Code FeaTure Envy sTench 6 If a meThod seems more inTeresTed in a class oTher Than The class iT acTually is in a Move MeThod move The meThod To The desired class 0 ExTracT MeThod if only parT of The meThod shows The sympToms February 14 2005 Bad Smells in Code PrimiTive Obsesston sTench 3 PrimiTive Types inhibiT change I Replace DaTa Value wiTh ObjecT on individual daTa values a Move MeThodField pull all The changes inTo a single class 0 InTroduce ParameTer ObjecT for signaTures I Replace Array wiTh ObjecT To geT rid of arrays February 14 2005 Bad Smells in Code SwiTch 5TaTen7enTs sTench 5 SwiTch sTaTemenTs lead To duplicaTion and inhibiT change I ExTracT meThod To remove The swiTch I Move meThod To geT The meThod where polymorphism can apply I Replace Type Code wiTh STaTeSTr39aTegy seT up inheriTance I Replace CondiTional wiTh Polymorphism geT rid of The swiTch February 14 2005 I Bad Smells in Code Lazy Class sTench 4 If a class eg a er refacToring does noT do much eliminaTe iT I Collapse Hierarchy for subclasses I Inline Class remove a single class February 14 2005 75 Bad Smells in Code Parallel InheriTance Hierarchies sTench 6 If when ever you make a subclass in one corner of The hierarchy you musT creaTe anoTher subclass in anoTher corner I Move MeThodField geT one hierarchy To refer To The oTher February 14 2005 74 Bad Smells in Code SpeculaTive eneraliTy sTench 4 If a class has feaTures ThaT are only used in TesT cases remove Them I Collapse Hierarchy for useless absTracT classes I Inline Class for useless delegaTion o Rename MeThod meThods wiTh odd absTracT names should be broughT down To earTh February 14 2005 76 Bad Smells in Code Bad Smells in Code Temporary Field sTench 3 Message Chains sTench 3 If a class has fields ThaT are only seT in special cases exTracT Them Long chains of messages To geT To a value are briTTle as any change in The inTermiTTenT sTrLIcTLIre will break The code I ExTracT Class for The special fields 0 Hide DelegaTe remove one link in a chain 9 ExTracT MeThod change The behavior To avoid chains February 14 2005 February 14 2005 Bad Smells in Code Bad Smells in Code Middle Man sTench 3 InappropriaTe InTimacy sTench 5 An inTermediary objecT is used Too ofTen To geT aT Classes are Too inTimaTe and spend Too much Time delving in encapsulaTed values each oTher39s privaTe parTs 0 Remove Middle Man To Talk direchy To The TargeT a Move MeThodField To separaTe pieces in order To reduce inTimacy 0 Replace DelegaTion wiTh InheriTance TLIrns The middle man inTo a o ExTracT Class make a common class of shared behaviordaTa subclass of The real objecT a Replace InheriTance wiTh DelegaTion when a subclass is geTTing Too cozy February 14 2005 February 14 2005 Bad Smells in Code Commenfs sfench 2 Commen rs are often a sign of unclear code consider refuc roring February 14 2005


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Jim McGreen Ohio University

"Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

Kyle Maynard Purdue

"When you're taking detailed notes and trying to help everyone else out in the class, it really helps you learn and understand the I made $280 on my first study guide!"

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"


"Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.