已閱讀5頁,還剩6頁未讀, 繼續(xù)免費閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
WhatIsanObject?Objectsarekeytounderstandingobject-orientedtechnology.Youcanlookaroundyounowandseemanyexamplesofreal-worldobjects:yourdog,yourdesk,yourtelevisionset,yourbicycle.Real-worldobjectssharetwocharacteristics:Theyallhavestateandbehavior.Forexample,dogshavestate(name,color,breed,hungry)andbehavior(barking,fetching,waggingtail).Bicycleshavestate(currentgear,currentpedalcadence,twowheels,numberofgears)andbehavior(braking,accelerating,slowingdown,changinggears).Softwareobjectsaremodeledafterreal-worldobjectsinthattheytoohavestateandbehavior.Asoftwareobjectmaintainsitsstateinoneormorevariables.Avariableisanitemofdatanamedbyanidentifier.Asoftwareobjectimplementsitsbehaviorwithmethods.Amethodisafunction(subroutine)associatedwithanobject.Definition:Anobjectisasoftwarebundleofvariablesandrelatedmethods.Youcanrepresentreal-worldobjectsbyusingsoftwareobjects.Youmightwanttorepresentreal-worlddogsassoftwareobjectsinananimationprogramorareal-worldbicycleasasoftwareobjectintheprogramthatcontrolsanelectronicexercisebike.Youcanalsousesoftwareobjectstomodelabstractconcepts.Forexample,aneventisacommonobjectusedinwindowsystemstorepresenttheactionofauserpressingamousebuttonorakeyonthekeyboard.Thefollowingillustrationisacommonvisualrepresentationofasoftwareobject.Asoftwareobject.Everythingthesoftwareobjectknows(state)andcando(behavior)isexpressedbythevariablesandthemethodswithinthatobject.Asoftwareobjectthatmodelsyourreal-worldbicyclewouldhavevariablesthatindicatethebicyclescurrentstate:Itsspeedis18mph,itspedalcadenceis90rpm,anditscurrentgearis5th.Thesevariablesareformallyknownasinstancevariablesbecausetheycontainthestateforaparticularbicycleobject;inobject-orientedterminology,aparticularobjectiscalledaninstance.Thefollowingfigureillustratesabicyclemodeledasasoftwareobject.Abicyclemodeledasasoftwareobject.Inadditiontoitsvariables,thesoftwarebicyclewouldalsohavemethodstobrake,changethepedalcadence,andchangegears.(Itwouldnothaveamethodforchangingitsspeedbecausethebikesspeedisjustasideeffectofwhichgearitsinandhowfasttheriderispedaling.)Thesemethodsareknownformallyasinstancemethodsbecausetheyinspectorchangethestateofaparticularbicycleinstance.Objectdiagramsshowthatanobjectsvariablesmakeupthecenter,ornucleus,oftheobject.Methodssurroundandhidetheobjectsnucleusfromotherobjectsintheprogram.Packaginganobjectsvariableswithintheprotectivecustodyofitsmethodsiscalledencapsulation.Thisconceptualpictureofanobjectanucleusofvariablespackagedwithinaprotectivemembraneofmethodsisanidealrepresentationofanobjectandistheidealthatdesignersofobject-orientedsystemsstrivefor.However,itsnotthewholestory.Often,forpracticalreasons,anobjectmayexposesomeofitsvariablesorhidesomeofitsmethods.IntheJavaprogramminglanguage,anobjectcanspecifyoneoffouraccesslevelsforeachofitsvariablesandmethods.Theaccessleveldetermineswhichotherobjectsandclassescanaccessthatvariableormethod.RefertotheControllingAccesstoMembersofaClasssectionfordetails.Encapsulatingrelatedvariablesandmethodsintoaneatsoftwarebundleisasimpleyetpowerfulideathatprovidestwoprimarybenefitstosoftwaredevelopers:Modularity:Thesourcecodeforanobjectcanbewrittenandmaintainedindependentlyofthesourcecodeforotherobjects.Also,anobjectcanbeeasilypassedaroundinthesystem.Youcangiveyourbicycletosomeoneelse,anditwillstillwork.Information-hiding:Anobjecthasapublicinterfacethatotherobjectscanusetocommunicatewithit.Theobjectcanmaintainprivateinformationandmethodsthatcanbechangedatanytimewithoutaffectingotherobjectsthatdependonit.Youdontneedtounderstandabikesgearmechanismtouseit.WhatIsaMessage?Asingleobjectalonegenerallyisnotveryuseful.Instead,anobjectusuallyappearsasacomponentofalargerprogramorapplicationthatcontainsmanyotherobjects.Throughtheinteractionoftheseobjects,programmersachievehigher-orderfunctionalityandmorecomplexbehavior.Yourbicyclehangingfromahookinthegarageisjustabunchofmetalandrubber;byitself,itisincapableofanyactivity;thebicycleisusefulonlywhenanotherobject(you)interactswithit(bypedaling).Softwareobjectsinteractandcommunicatewitheachotherbysendingmessagestoeachother.WhenobjectAwantsobjectBtoperformoneofBsmethods,objectAsendsamessagetoobjectB(seethefollowingfigure).Objectsinteractbysendingeachothermessages.Sometimes,thereceivingobjectneedsmoreinformationsothatitknowsexactlywhattodo;forexample,whenyouwanttochangegearsonyourbicycle,youhavetoindicatewhichgearyouwant.Thisinformationispassedalongwiththemessageasparameters.Messagesuseparameterstopassalongextrainformationthattheobjectneedsinthiscase,whichgearthebicycleshouldbein.Thesethreepartsareenoughinformationforthereceivingobjec
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030人工智能芯片行業(yè)市場前景分析與發(fā)展布局規(guī)劃
- 2025-2030人工智能機器人行業(yè)市場深度調(diào)研及發(fā)展趨勢和前景預(yù)測研究報告
- 2025-2030人工智能教育行業(yè)市場發(fā)展現(xiàn)狀與投資機會評估規(guī)劃研究
- 2025-2030人工智能技術(shù)應(yīng)用之道業(yè)融合狀況研究與未來發(fā)展趨勢分析
- 2025-2030人工智能客服系統(tǒng)市場現(xiàn)狀供需分析及投資評估規(guī)劃分析研究報告
- 2025-2030人工智能在制造業(yè)的應(yīng)用研究深度報告及企業(yè)轉(zhuǎn)型與效率提升全新研究全景圖
- 2025-2030人工智能醫(yī)療影像識別準確率提升路徑與技術(shù)應(yīng)用
- 2025-2030人工智能產(chǎn)業(yè)發(fā)展現(xiàn)狀與核心技術(shù)突破及市場化投資方向建議分析報告
- 2025-2030交通運輸輔助設(shè)備制造業(yè)市場供需動態(tài)監(jiān)測及智能交通系統(tǒng)研發(fā)規(guī)劃
- 2025-2030交通運輸設(shè)備行業(yè)市場宏觀探討及技術(shù)創(chuàng)新與產(chǎn)業(yè)升級報告
- 個人年度工作計劃及職業(yè)發(fā)展規(guī)劃-適用于各行各業(yè)
- 交通運輸企業(yè)安全生產(chǎn)風(fēng)險分級管控體系細則
- 2025年稅務(wù)技能大賽試卷及答案
- 康復(fù)科院感知識培訓(xùn)課件
- 2025年及未來5年中國草本植物飲料行業(yè)市場深度分析及投資戰(zhàn)略研究報告
- 不說臟話課件
- 2025至2030中國粉防己提取物行業(yè)項目調(diào)研及市場前景預(yù)測評估報告
- 血液系統(tǒng)疾病研究-洞察及研究
- 企業(yè)監(jiān)察制度管理辦法
- 建筑施工消防安全管理
- 國家電網(wǎng)公司電力安全工作規(guī)程(線路)
評論
0/150
提交評論