




已閱讀5頁,還剩6頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rè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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025至2030工模鋼產(chǎn)業(yè)市場(chǎng)深度調(diào)研及發(fā)展趨勢(shì)與發(fā)展趨勢(shì)分析與未來投資戰(zhàn)略咨詢研究報(bào)告
- 2025至2030鋯英砂行業(yè)市場(chǎng)深度研究與戰(zhàn)略咨詢分析報(bào)告
- 精準(zhǔn)醫(yī)療與智慧健康管理行業(yè)的未來展望
- 2025至2030高密度元件市場(chǎng)前景分析及發(fā)展趨勢(shì)分析與未來投資戰(zhàn)略咨詢研究報(bào)告
- 四川省德陽市名校2024年數(shù)學(xué)八上期末質(zhì)量跟蹤監(jiān)視模擬試題含解析
- 北京順義2024-2025學(xué)年八上物理期末調(diào)研試題含解析
- 激光雕刻機(jī)生產(chǎn)制造項(xiàng)目投資分析報(bào)告
- 安全生產(chǎn)四不放過指什么
- 企業(yè)消防安全制度模板
- 安全生產(chǎn)責(zé)任落實(shí)原則
- 安保工作月度總結(jié)
- 開業(yè)美容項(xiàng)目活動(dòng)方案
- 2025年技術(shù)玻璃制品行業(yè)市場(chǎng)調(diào)研報(bào)告
- 2025至2030高純氯化鉀行業(yè)產(chǎn)業(yè)運(yùn)行態(tài)勢(shì)及投資規(guī)劃深度研究報(bào)告
- 黨課課件含講稿:以作風(fēng)建設(shè)新成效激發(fā)干事創(chuàng)業(yè)新作為
- 2025年度職業(yè)技能鑒定國家題庫維修電工高級(jí)技師復(fù)習(xí)題庫及答案(完整版)
- 安措費(fèi)使用計(jì)劃報(bào)審表(施工報(bào)-監(jiān)理審-業(yè)主批)
- Q∕SY 02625.2-2018 油氣水井帶壓作業(yè)技術(shù)規(guī)范 第2部分:設(shè)備配備、使用與維護(hù)
- 調(diào)研報(bào)告:農(nóng)村糧食經(jīng)紀(jì)人現(xiàn)狀、存在問題及建議
- 鋼筋平行檢驗(yàn)記錄范本
- 2021-2022學(xué)年安徽省蚌埠市高一下學(xué)期期末數(shù)學(xué)試題【含答案】
評(píng)論
0/150
提交評(píng)論