Essentially, thenoobjectpatternisgoingtobeusedanytimethatyouhave a knollobjectbeingreturned.
Sothekeywordno, in a programminglanguage, that's hisjobscriptbeingreturned.
Sonormallywhenyoudothat, youhavetocheckifsomethingisequaltoknowbeforeyouactuallyaccessthedifferentpropertiesonthatnoproperobjectbecauseifyouaccess a method, forexample, on a noobject, you'regoingtogetit.
Andifit's noshowsomedefaultimage, forexample, orifit's not, no, thenjustshowtheimageitself.
Butifyou'reusing a metalobjectpattern, thisimagepropertywilljustreturn a knollobjectoftheimage, whichwouldjustbe a defaultimage, forexample, thatyouwouldbedisplayinginsteadoftheactualimage.
Soeverytimeyougottheimageofanitem, youwouldreturnthisknollimage, whichwouldactexactlythesameas a normalimageobject.
Butitwouldjusthavedefaultvalues, suchas a defaultimagethatitwouldbedisplayinginsteadoftheactualimageoftheitem.
A commonplacethatthisisusediswithuseraccounts, becausemanywebsiteshaveanoptionforyoutosignintoaccount.
Andifyou'renotsigninyourbeingtreatedas a guestuser, solittleshowthatyou're a guest.
Maybeinthecornerofthedisplayofthewebsite, andyou'llhavecertainpermissionlevelswhereyoucanaccesssomethingsbutnototherthings, becauseyou'reonly a guestandnotsignedit.
Solet's take a lookatanexampleofwhatwehave a usersystem.
Wehavetochangeiteverywhereelseinourcode, whichis a terriblethingtodobecauseit's soeasytomiss a singleplacewhereit's used, andit's veryhardtofindthaterror.
Ifyoudomake a WR, it's alsoveryeasytoforgettocheckfornofortheuser.
Sothen, ifweprint 1/3 user, whichisgoingtobe a userthatdoesnotexist, you'llseethatPrince.
Hello, guest.
You'renotallowedhere.
Andthat's becausedownhereinourcode, wehaveallofourdifferentknollchecks, checkingtomakesureifwehave a nousertotreatitin a specialcasebyprintingoutguestasthenameandtomakesuretosaythattheydon't haveaccessinsteadofcalling a functionthatdoesn't existonthatnoobject.
Thisis a verycommonthingtodowiththenoobjectpatternbyprefixingthenameoftheclasswithnotosay, ThisistheKnollversionoftheobjectortryingtorepresentandarenoobjectisnotgoingtotakeany I D ornamebecauseit's justgoingtohavesomedefault.
Propertieswillgiveit a defoe i d ofnegativeone.
Andthenthenameisguest.
Sincethat's thenamewe'retryingtoprintoutdownhere.
Wewantguesttobeourdefaultname, and a guestuserwillneverhaveanyaccessonourwebsite.
Sonowifwegointoourbrowserhereandwerunthisprintuserfunction, so I sayPrintUserandwegiveitanideaofone, forexample, which, asweknow, isouruserBob, whowillhaveaccessduetothisfunction.
And I haveallthesedifferentcodeexamplesonmygethubpagethatyoucanview, whichislinkedinthedescriptionandmypinnedcommentbelow.
Somakesureyoucheckthatout.
Ifyou'reinterestedindissectingthiscodeinmoredepth, I have a bunchofcommentsinthereexplaininghoweverythingworks.
Andifyou'restillconfusedafterlookingatallthat, pleasemakesuretoleave a commentdownbelow, askingmeanyofthequestionsthatyouguyshaveproblemswith.
Sothankyouguysverymuchforwatchingthisvideo.
I hopeyoulearnedsomethingaboutthenoobjectpattern, and I hopethiswhatdidyourappetite a littlebitfor?
Wantedtolearnmoreabouthowyoucancreatecleanerstylecodethatwillsaveyou a bunchofheadachesinthefuture, andifso, makesuretocheckouttherestofmydesignpatternvideoscominginthefuture.
Thankyouguysagainforwatchingthisvideo.
Have a goodday.
Hello, everybody.
Subtitles and vocabulary
Click the word to look it upClick the word to find further inforamtion about it