由于stackoverflow上已有人提出過這個問題,并且解答也很好,我就直接搬運最高票過來,并稍作翻譯。Encapsulationofbehaviorassociatedwithgettingorsettingtheproperty-thisallowsadditionalfunctionality(likevalidation)tobeaddedmoreeasilylater.對與get&set類屬性有關的類的行為進行封裝可以方便以后增加其他功能(比如驗證)Hidingtheinternalrepresentationofthepropertywhileexposingapropertyusinganalternativerepresentation.用不同于內部的展現方式對外公布屬性Insulatingyourpublicinterfacefromchange-allowingthepublicinterfacetoremainconstantwhiletheimplementationchangeswithoutaffectingexistingconsumers.避免對外接口發生變化——當實現發生變化時,對外接口不變,不會影響到現有的調用方Controllingthelifetimeandmemorymanagement(disposal)semanticsoftheproperty-particularlyimportantinnon-managedmemoryenvironments(likeC++orObjective-C).控制屬性的生命周期和內存管理——在無內存管理的環境中尤其重要(比如C++和Objective-C)Providingadebugginginterceptionpointforwhenapropertychangesatruntime-debuggingwhenandwhereapropertychangedtoaparticularvaluecanbequitedifficultwithoutthisinsomelanguages.當屬性的值在運行時發生變化的時候,提供一個調試入口——在某些語言中調試屬性值的變化是很困難的Improvedinteroperabilitywithlibrariesthataredesignedtooperateagainstpropertygetter/setters-Mocking,Serialization,andWPFcometomind.提高與那些操作屬性的getter/setter的庫的互通性——比如Mocking(單測常用的東西,我平時也直接說Mock,不知道怎么翻譯),序列化,WPF等等Allowinginheritorstochangethesemanticsofhowthepropertybehavesandisexposedbyoverridingthegetter/settermethods.允許子類繼承并覆寫修改屬性的行為的語義Allowingthegetter/settertobepassedaroundaslambdaexpressionsratherthanvalues.允許getter/setter作為lambda表達式而不是值進行傳遞Gettersandsetterscanallowdifferentaccesslevels-forexamplethegetmaybepublic,butthesetcouldbeprotected.getter/setter可以有不同的可訪問性,比如get可以public而set則是protected