計(jì)算機(jī)外文翻譯--c#設(shè)計(jì)模式_第1頁(yè)
已閱讀1頁(yè),還剩13頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、<p><b>  外文科技資料翻譯</b></p><p><b>  英文原文</b></p><p>  Design Patterns in C#設(shè)計(jì)模式C #</p><p>  A model is a program using such a program, we can complete cer

2、tain tasks. A model is a way through this way, we can achieve a certain purpose. Meanwhile, a model is a technology. In order to complete a particular job, we need to access and use the technology effectively. This kind

3、of thinking can be applied to many types of work, such as : cooking, pyrotechnic, software development and other work. If the work Township respective fields is not of sound, then the practitioners in the field will be&l

4、t;/p><p>  Christopher Alexander is that some of the best skills facts old road program modeled on the one of the pioneers. His research area is the architecture, not the software. In his new book, "A Patt

5、ern Language : Towns, Buildings, Construction book, "Alexander the construction of housing and urban building the successful model. Alexander's works have far-reaching effects, it also affects software fields. T

6、his Department has been able to make an impact in other areas, partly because the author has a </p><p>  You might think that the construction approach is aimed at "building design." But Alexander

7、made clear, Application architecture model, which aims to serve the future to those living in these buildings or living in these cities people, make them feel comfortable and happy. Alexander's work showed that the m

8、odel is a certain access and the exchange of technical knowledge in the field excellent way. He also pointed out that a reasonable understanding of a particular record and the object of the ex</p><p>  Softw

9、are development groups have to have a model resonates, and published a large number of books to record the software development model. These books record the software process the best time, senior architecture and softwa

10、re design category level, and and the pattern books are still published. If you need to choose the mode of translation of the books, You should first take some time to read those to the secretary of the published comment

11、s, and then from the translation of choice for your hel</p><p>  Abstract, a kind of interface is the kind of certain methods and fields consisting of a pool. Other examples of the object can be set right th

12、rough this class for a visit. Excuse the expression usually implementation of the method of operation for the functional responsibility, which often means using the name, code Notes and other documents for descriptive. C

13、ategory 1 refers to the realization of the type of method to achieve code. </p><p>  C # language to improve the interface concept, so that it can be a separate structure, thereby interface (namely : an obje

14、ct must do what) and the realization (that is : a target how to meet their functional responsibilities) to effectively separate areas. C # language interface to allow for more than one category with a functional, and the

15、 C # interface can achieve more than one type interface. </p><p>  There are several design patterns can be used for the C # features. For example : we can use an interface to fit a certain type of interface

16、, In reality, this is through the application adapter mode to meet a customer's needs. To discuss some language C # unable to complete the work, we should understand how the C # language is the work performed, Theref

17、ore, we first discuss the C # language interface. </p><p>  If you do not use interface, then you can use the abstract class (C + + language abstract). However, the n layer (n-tier) software development and

18、definition of structure and other objects, the interface has a critical role to play. Similarly, if you do not use commissioned, then you can use the interface. If a public mandate required to be registered for a callbac

19、k method, then the commission could improve these mandates, and therefore C # Entrusted language is a very useful content. </p><p>  1.Interface and abstract category </p><p>  Please indicate

20、the C # language and abstract category of the three interfaces between different. </p><p>  In use, failed to provide a method of non-abstract category with an abstract interface is similar. However, we need

21、 to pay attention to the following points : </p><p>  A class can achieve any number of interfaces, but only up to an abstract category of sub-categories. </p><p>  An abstract class can include

22、 abstract, and an interface all methods in effect are abstract. </p><p>  An abstract class can declare and use variables, and not an interface. </p><p>  An abstract category of the visit Xiuch

23、ifu can be public, internal, protected, protected internal or private, and members of the interface visit Xiuchifu in default under are public, but, in a statement Interface members, allowed to use the visit Xiuchifu (ev

24、en allowed to use public visit Xiuchifu). </p><p>  An abstract class can be defined Constructors, and not an interface. </p><p>  2.Interface with the commissioning </p><p>  Inte

25、rface with the commissioning of comparison : </p><p>  Interface with the commissioning of the similarities is that they can have the desired definition of the function. We learn in the process of commission

26、ing often create some confusion and the reason was partly due to "trust" the word It can express meaning is nuanced different concepts. The right to commission and compare interface, we have to take a look at t

27、he C # language commission is how to work. </p><p>  C # language keyword delegate introduction of a new type of commission, This new type commissioned determine what type of method can be used only example

28、of this type of commission. Commissioned no standard type of name, but it standardized the method parameter types and return types. </p><p>  We consider the following statement : </p><p>  Pub

29、lic delegate object BorrowReader ( IDataReader reader); </p><p>  This statement of the Declaration of a new type of commission. Commissioned by the name of the type BorrowReader. The statement said the comm

30、ission can use any type of technique is, as long as the method of receiving a IDataReader object as a method parameters, and return types of methods to object. If a certain category is the following : </p><p&g

31、t;  Pricate static object GetNames (IDataReader reader) </p><p><b>  {</b></p><p><b>  //…</b></p><p><b>  }</b></p><p>  GetNames (

32、) method parameter types and return types to meet BorrowReader commissioned by the types of standardized definition, this method can be used to name the types commissioned example, Examples of the statement is as follows

33、 : </p><p>  Is a variable b BorrowReader commissioned by the types of examples. Any visit to the commission examples of code can be called Object b, then commissioned example of the calling object b inclusi

34、ve approach. The reason why the use of object example b, as this program has the following advantages : other ways in the right time calling object b and an inclusive approach. For example : a category of data services a

35、vailable to read on a database, called a BorrowReader commissioned example (that is, t</p><p>  C # interface can be an inclusive, C # attributes (property), and indexer. Interface can be a tolerant, inclusi

36、ve but not commissioned. Why? </p><p>  We can simply gives the following explanation : </p><p>  Delegate keyword introduction of a new type, and the event keyword introduction of a new member.

37、 A statement standardized interfaces members, and not the type, time can be classified interface, which can not be classified as commissioned interface. </p><p>  And detailed explanation : </p><p

38、>  Event keyword statement of a specific type of field (an "incident") standardize the types (must be a commissioned type) and their names. C # restrictions on the visit, the customer can not use the inciden

39、t type (commissioned by the type) of all acts. Customers can only use commissioned by the + = and -= acts. Such restrictions are the result of : Only statement classes can call (or excited) an incident. However, as long

40、as inclusive so that a certain category of a public member of the incident, </p><p>  When entrusted to a single callback method, one based on interface design is equally effective. However, if the design ne

41、eds to hold the commissioning of Togo and called method, then entrusted clearer. When a particular target for the use of a commissioned for a number of clients (for example, "hits" on the incident) for the regi

42、stration, this advantage is particularly prominent. Is a one time member, the member can make an object or class to give notice to the news. </p><p>  Understand the language C # commissioned may be difficul

43、t, especially because we repeat the definition of "trust" the meaning of the term. For example, we can use the "commission" of the term commission statement said a commission types, and even commissio

44、ned an example. Particularly, people always say, "Call a commission," but an object can only call a commissioned example, not calling a commissioned type. If you feel this is part of some confusion hard, do not

45、 worry, a lot of people are. But w</p><p>  3.Interface and attributes </p><p>  C # language can be an excuse for standardized interface must provide the indexer or C # attributes. If your def

46、inition of a new type of set, then we need to standardize an indexer. If you make the following statement, a realization that must include a method and the method to use an attribute value, and (or) the need to set this

47、attribute value, then you will need a standard C # attributes. </p><p>  Following is a statement of a code without the use of C # attributes interface, but the realization, the need for a targeting of the a

48、ttributes of the visit. Public interface IAdvertisement </p><p><b>  {</b></p><p>  Int GetID (); </p><p>  String GetADCopy (); </p><p>  Void SetADCopy (s

49、tring text); </p><p><b>  }</b></p><p>  The above code interface is Oozinoz system Showproperties part of the library. In simple terms, this meant to standardize the interface of tw

50、o C # attributes, but strictly speaking, they are not C # attributes. The use of C # syntax for C # attributes the advantage of its syntax more elegant. However, the most important point is not to have the capacity to fo

51、resee the reflection customers can detect the presence of C # attributes. For example, as long as the relevant attribute is the real target</p><p>  In an interface, C # attributes expressed in the syntax is

52、 dependent, and therefore in achieving interface will have some differences. We should use in-depth understanding of C # interface characteristics of the relevant concepts and the use of details. </p><p>  4

53、.Interface details </p><p>  C # interface of the main advantages is that the interface of object interaction of the restrictions. Such restrictions are, in fact, a liberation. On the realization of a certa

54、in type of interface, the category The interface in the provision of services in the process has undergone many changes, But these changes will not affect the class customers. Although excuses are very easy to understand

55、, but in time, Also details of the development staff have been forced to resort to reference materials.</p><p>  Interface description of the types of interaction in the process of the expectations and do no

56、t expect to conduct acts. Interface with pure abstract categories is very similar, interface definition it should be completed in the function, but we did not achieve these functions. Interface is also entrusted with a s

57、imilar course, entrusted only to standardize the method of each method parameter and return types. </p><p>  Also commissioned type, it can not be an inclusive one interface commissioned and treat it as a me

58、mber. However commissioned by the types of variables and marking the event keyword variables could happen in interface. </p><p>  Apart from the methods and events, but also inclusive interface for indexing

59、and attributes. These elements of the syntax is very important because customers through the use of these types of members and the use of reflection, Detection and understanding to achieve category (category refers to ac

60、hieve the realization of Interface) behavior. Grasp how to use the C # interface concept and very important details, that you deserve to spend some time. This part of this function is also a powerful sen</p><p

61、>  5.General Interface can not provide the content </p><p>  C # interface can be used to simplify and strengthen the system design, of course, Sometimes the excuse that may be beyond the general interfa

62、ce definition and scope of use. </p><p>  If you want to make a kind of interface with a customer expectations interface adapter, the adapter can be applied to model. </p><p>  If you want to se

63、t such a simple interface, then the model can be applied appearance. </p><p>  If you want a definition of interface, so that it can be used to delay object, can be applied to the target group. Well, we can

64、use synthetic model. </p><p>  If you want to achieve an abstract for their separation, so that they can change independently, then can be applied to bridge mode. </p><p>  Each model is designe

65、d to : in a specific context solve a problem. Based on the model interface emphasized the context, Context because the decision whether we need to define or redefine the right of the visit means These methods can be both

66、 a class method, it can also be a cluster approach. For example : If a particular category of what we need, However method name with the customer expectation of a name does not match, Then we can use Adapter model to sol

67、ve this problem. </p><p>  If a client calls us to develop the code, so this is a target customers. In some cases, client code in the code only after the completion of the development, So developers can ask

68、 the households can conform to our code of the object interface specification. However, in some cases, families may also be independent of code development. For example : a rocket simulation program we need to use the in

69、formation provided by the rocket, However simulation program also defines the rocket's working metho</p><p>  Java programming language and the language differences between the lies : C # Language no way

70、 any possible Cook Up Some of the anomalies in a statement. Whether this is a good character? Please give your conclusions and related reasons. </p><p>  In a way other than the first statement of anomalies

71、because : </p><p>  We should first of all pay attention to, the Java language does not require a statement of all possible methods dished out anomalies. For example, any methods may encounter a space pointe

72、r and then dished out a statement not abnormal.Even the Java language designers admit that forced programmers all possible statement is a very unrealistic. Applications need a strategy, and under this strategy to deal wi

73、th all the anomalies. Developer statement requested some type of anomaly is not a substitute</p><p>  The other : programmers should be all they can receive help. Indeed, an application architecture should

74、have a credible strategy to deal with the anomalies. Meanwhile, forced developers in each of the methods are common problems (such as empty pointer) statement is unrealistic. For certain types of errors, such as open a f

75、ile may arise in the course of the issue, there is a definite need for methods the caller to deal with the anomalies that may occur. C # language for a method statement termino</p><p>  Object-oriented progr

76、am design procedures can be avoided is not designed for a single, thus avoiding the procedures of the various parts are mixed together. An ideal object-oriented application should be one of the smallest category, This ca

77、tegory could include other reusable kind of behavior effectively together.</p><p><b>  中文譯文</b></p><p><b>  C#設(shè)計(jì)模式</b></p><p>  一個(gè)模式是一種方案,利用這種方案,我們可以完成某項(xiàng)工作。一

78、個(gè)模式也是一種途徑,通過這種途徑,我們可以達(dá)到某個(gè)目的。同時(shí),一個(gè)模式也是一種技術(shù)。為了完成某項(xiàng)工作,我們必須獲取并利用有效的技術(shù)。這種思想可以應(yīng)用于多種工作,例如:做飯、制造煙火、開發(fā)軟件以及其他工作。如果某鄉(xiāng)工作所屬的領(lǐng)域正在不段的完善,那么,這個(gè)領(lǐng)域的從業(yè)人員會(huì)去尋找一些通用的、有效的解決方案,利用這些方案,在不用的環(huán)境下解決相關(guān)問題,從而達(dá)到完成工作的目的。某個(gè)領(lǐng)域的從業(yè)人員經(jīng)常會(huì)產(chǎn)生該領(lǐng)域的習(xí)慣用語(yǔ),這些習(xí)慣用語(yǔ)有助于相關(guān)人員

79、對(duì)工作進(jìn)行交流。模式也是一些習(xí)慣用語(yǔ)。所謂模式,就是一些能夠完成特定任務(wù)并達(dá)到任務(wù)目標(biāo)的現(xiàn)成技術(shù)。隨著某項(xiàng)技術(shù)及相關(guān)習(xí)慣用語(yǔ)的發(fā)展,一些人將這項(xiàng)技術(shù)及模式記錄成文,這些記錄下來的文獻(xiàn)使習(xí)慣用語(yǔ)得到標(biāo)準(zhǔn)化,并使一些行之有效的技術(shù)得到了廣泛傳播。</p><p>  Christopher Alexander 就是把某種技巧的最佳事實(shí)方案舊路為模式的先驅(qū)者之一。他的研究領(lǐng)域是建筑學(xué),而不是軟件。在其著作《A Patt

80、ern Language:Towns,Buildings,Construction》一書中,Alexander提出了建造房屋和建設(shè)城市的成功模式。Alexander的著作影響深遠(yuǎn),因此也影響到軟件領(lǐng)域。這部著作之所以能夠影響到其他領(lǐng)域,部分也是因?yàn)樽髡邔?duì)目的具有獨(dú)特的觀察方式。</p><p>  你可能會(huì)認(rèn)為,建筑模式的目的就是“設(shè)計(jì)建筑”。但是Alexander明確提出,應(yīng)用建筑模式的目的是服務(wù)于那些以后要居

81、住在這些建筑物內(nèi)或居住在這些城市中的人們,并使他們感到舒適和欣慰。Alexander的工作表明,模式是一種獲取并交流某個(gè)技術(shù)領(lǐng)域知識(shí)的極好途徑。同時(shí)他也指出,合理地認(rèn)識(shí)并記錄某項(xiàng)工作的目的是非常關(guān)鍵的,這需要哲學(xué)的思考,同時(shí)還面臨著難以捉摸的挑戰(zhàn)。</p><p>  軟件開發(fā)群體已經(jīng)對(duì)模式產(chǎn)生了共鳴,并出版了大量著作來記錄軟件開發(fā)的模式。這些書籍記錄了軟件過程的最佳時(shí)間、高級(jí)體系結(jié)構(gòu),以及軟件在類級(jí)別的設(shè)計(jì),同

82、時(shí),與模式有關(guān)的新書還在不斷出版。如果你需要選擇譯本有關(guān)模式的書籍,你應(yīng)該首先花一些時(shí)間去讀一讀那些對(duì)已出版書記的評(píng)論,然后,從中選擇譯本對(duì)你幫助最大的書籍,并將其作為你的學(xué)習(xí)對(duì)象。</p><p>  抽象的說,一個(gè)類的接口是由這個(gè)類的某些方法和字段構(gòu)成的一個(gè)集合。其他類的對(duì)象實(shí)例可以通過這個(gè)集合對(duì)這個(gè)類進(jìn)行訪問。借口通常表達(dá)了方法執(zhí)行的操作所提供的功能職責(zé),這些職責(zé)往往用方法的名稱、代碼注釋,以及其他文檔進(jìn)行

83、描述說明。一個(gè)類的實(shí)現(xiàn)指的是在類方法中實(shí)現(xiàn)的代碼。</p><p>  C#語(yǔ)言改進(jìn)了接口的概念,使之可以單獨(dú)進(jìn)行構(gòu)造,從而把接口(即:一個(gè)對(duì)象必須做什么)和實(shí)現(xiàn)(即:一個(gè)對(duì)象如何滿足其功能職責(zé))有效地區(qū)分開來。C#語(yǔ)言的接口允許多個(gè)類提供同一個(gè)功能,同時(shí),C#的接口也可以使一個(gè)類實(shí)現(xiàn)多個(gè)接口。</p><p>  有好幾個(gè)設(shè)計(jì)模式可以利用C#所提供的特征。例如:我們可以用一個(gè)接口來適配某

84、個(gè)類的接口,這實(shí)際是通過應(yīng)用適配器模式來滿足一個(gè)客戶的需求。為了討論某些無(wú)法用C#語(yǔ)言完成的工作,我們應(yīng)該了解C#語(yǔ)言是如何完成工作的,所以我們首先討論C#語(yǔ)言的接口。</p><p>  如果你確實(shí)無(wú)法使用接口,那么,你可以使用抽象類(C++語(yǔ)言提供了抽象類)。然而,在n層(n-tier)軟件開發(fā)和對(duì)象定義構(gòu)造等方面,接口具有關(guān)鍵的作用。與此類似的是,如果你確實(shí)無(wú)法使用委托,那么你可以使用接口。如果某個(gè)公共任務(wù)

85、需要注冊(cè)一個(gè)方法來進(jìn)行回調(diào),那么,委托可以改進(jìn)這類任務(wù),因此,C#語(yǔ)言提供的委托是一項(xiàng)非常有用的內(nèi)容。</p><p><b>  接口與抽象類</b></p><p>  請(qǐng)指出C#語(yǔ)言的抽象類與接口之間的三種不同之處。</p><p>  在使用上,一個(gè)沒有提供非抽象方法的抽象類與一個(gè)接口是類似的。然而,我們需要注意以下幾點(diǎn):</p&

86、gt;<p>  一個(gè)類可以實(shí)現(xiàn)任意多個(gè)接口,但是最多只能對(duì)一個(gè)抽象類進(jìn)行子類化。</p><p>  一個(gè)抽象類可以包括非抽象方法,而一個(gè)接口的所有方法在效果上都是抽象的。</p><p>  一個(gè)抽象類可以聲明并使用變量,而一個(gè)接口不能。</p><p>  一個(gè)抽象類中的方法的訪問修飾符可以是public、internal、protected、p

87、rotected internal或者是private,而接口成員的訪問修飾符在默認(rèn)情況下都是public,而且,在聲明接口成員時(shí),不允許使用訪問修飾符(甚至不允許使用public訪問修飾符)。</p><p>  一個(gè)抽象類可以定義構(gòu)造函數(shù),而一個(gè)接口不能。</p><p><b>  接口與委托</b></p><p><b> 

88、 接口與委托的比較:</b></p><p>  接口與委托的相似之處在于它們都可以定義我們所期望的功能。我們?cè)趯W(xué)習(xí)使用委托的過程中經(jīng)常會(huì)產(chǎn)生一些混亂,究其原因,部分是由于“委托”這個(gè)詞,它可以表達(dá)含義具有微小差別的不同概念。在對(duì)委托和接口進(jìn)行比較之前,我們有必要回顧一下委托在C#語(yǔ)言中是如何工作的。</p><p>  C#語(yǔ)言的關(guān)鍵字delegate引入了一種新的委托類型,

89、這種新的委托類型可以確定什么類型的方法才可以用于實(shí)例化這種委托類型。委托類型沒有規(guī)范方法的名稱,但是它規(guī)范了方法的參數(shù)類型和返回類型。</p><p><b>  我們考慮以下聲明:</b></p><p>  Public delegate object BorrowReader(IDataReader reader);</p><p>  

90、這條語(yǔ)句聲明了一個(gè)新的委托類型。委托類型的名稱是BorrowReader。聲明指出該委托類型可以用任何方法進(jìn)行實(shí)例化,只要這個(gè)方法接收一個(gè)IDataReader對(duì)象作為方法參數(shù),并且方法返回類型為object。假定某個(gè)類中有以下方法:</p><p>  Pricate static object GetNames(IDataReader reader)</p><p><b>

91、  {</b></p><p><b>  //…</b></p><p><b>  }</b></p><p>  GetNames()方法的參數(shù)類型和返回類型滿足BorrowReader委托類型的規(guī)范定義,因此可以使用這個(gè)方法名稱對(duì)委托類型進(jìn)行實(shí)例化,實(shí)例化語(yǔ)句如下:</p><p&g

92、t;  變量b是一個(gè)BorrowReader委托類型的實(shí)例。任何能夠訪問該委托實(shí)例的代碼都可以調(diào)用對(duì)象b,然后委托實(shí)例將調(diào)用對(duì)象b包容的方法。之所以使用對(duì)象實(shí)例b,是因?yàn)檫@個(gè)方案具有以下優(yōu)點(diǎn):其他方法可以在合適的時(shí)候調(diào)用對(duì)象b及其包容的方法。例如:一個(gè)數(shù)據(jù)服務(wù)類可以獲得一個(gè)數(shù)據(jù)庫(kù)讀取器,調(diào)用一個(gè)BorrowReader委托實(shí)例(即把上述讀取器傳遞給這個(gè)委托實(shí)例),然后把這個(gè)數(shù)據(jù)庫(kù)讀取器作為一個(gè)資源進(jìn)行釋放。</p><

93、;p>  一個(gè)C#接口可以包容方法、C#屬性(property),以及索引器。一個(gè)接口也可以包容時(shí)間,但是不能包容委托。為什么?</p><p>  我們可以簡(jiǎn)單地給出以下解釋:</p><p>  Delegate關(guān)鍵字引入了一個(gè)新的類型,而event關(guān)鍵字引入了一個(gè)新的成員。一個(gè)接口聲明規(guī)范了成員,而不是類型,因此時(shí)間可以歸入接口,而委托不能歸入接口。</p>&l

94、t;p><b>  而詳細(xì)的解釋是:</b></p><p>  Event關(guān)鍵字聲明了一個(gè)特定類型的字段(一個(gè)“事件”),規(guī)范了其類型(必須是一個(gè)委托類型)及其名稱。C#限制了對(duì)事件的訪問,客戶不能使用事件類型(其委托類型)的所有行為??蛻糁荒苁褂梦兴峁┑?=和-=行為。這種限制所產(chǎn)生的結(jié)果之一是:只有聲明類可以調(diào)用(或激發(fā))一個(gè)事件。但是,只要使某個(gè)類包容一個(gè)public事件成

95、員,一個(gè)接口客戶的組成類就可以實(shí)例化上述那個(gè)類。因?yàn)槭录且粋€(gè)類的接口的標(biāo)準(zhǔn)組成部分,因此我們有充分的理由讓接口包括事件。</p><p>  當(dāng)采用委托對(duì)單個(gè)方法進(jìn)行回調(diào)時(shí),一個(gè)基于接口的設(shè)計(jì)是同樣有效的。但是如果設(shè)計(jì)中需要使用委托來持有并調(diào)用多哥方法時(shí),那么,采用委托更為清晰。特別是當(dāng)一個(gè)對(duì)象使用一個(gè)委托讓多個(gè)客戶對(duì)一個(gè)事件(例如“點(diǎn)擊”事件)進(jìn)行注冊(cè)的時(shí)候,這個(gè)優(yōu)點(diǎn)尤其突出。一個(gè)時(shí)間是一個(gè)成員,這個(gè)成員可以

96、使一個(gè)對(duì)象或者類提供通知消息。</p><p>  理解C#語(yǔ)言的委托可能非常困難,特別是因?yàn)槲覀冎貜?fù)定義了“委托”這個(gè)術(shù)語(yǔ)的意義。例如,我們可以使用“委托”這個(gè)術(shù)語(yǔ)表示一個(gè)委托聲明、委托類型,甚至一個(gè)委托實(shí)例。特別是,人們經(jīng)常說“調(diào)用一個(gè)委托”,但是一個(gè)對(duì)象只能調(diào)用一個(gè)委托的實(shí)例,而不能調(diào)用一個(gè)委托的類型。如果你感覺這部分內(nèi)容有些混亂難解,別擔(dān)心,很多人都是如此。但是我們確實(shí)應(yīng)該認(rèn)真研究在C#中委托是如何工作的

97、,因?yàn)檫@不僅是理解應(yīng)用程序如何工作的關(guān)鍵,也是理解類之間如何進(jìn)行交互的關(guān)鍵。</p><p><b>  接口與屬性</b></p><p>  C#語(yǔ)言的借口可以規(guī)范接口實(shí)現(xiàn)必須提供的索引器或者C#屬性。如果你定義了一個(gè)新的集合類型,那么就需要規(guī)范一個(gè)索引器。如果你做出了以下聲明,即某個(gè)實(shí)現(xiàn)中必須包括一個(gè)方法,而這個(gè)方法要使用一個(gè)屬性值,并且(或者)需要設(shè)置這個(gè)屬性

98、值,那么,你就需要規(guī)范一個(gè)C#屬性。</p><p>  以下代碼聲明了一個(gè)沒有使用C#屬性的接口,但是在實(shí)現(xiàn)時(shí),需要提供對(duì)一個(gè)廣告對(duì)象的屬性的訪問。</p><p>  Public interface IAdvertisement</p><p><b>  {</b></p><p>  Int GetID();&

99、lt;/p><p>  String GetADCopy();</p><p>  Void SetADCopy(string text);</p><p><b>  }</b></p><p>  上述代碼中的接口是Oozinoz系統(tǒng)中Showproperties類庫(kù)的一部分。簡(jiǎn)單說來,這個(gè)接口為其實(shí)現(xiàn)規(guī)范了兩個(gè)C#屬性

100、,但嚴(yán)格說來,它們并非C#屬性。使用C#的語(yǔ)法進(jìn)行C#屬性規(guī)范的優(yōu)點(diǎn)是其語(yǔ)法比較優(yōu)雅。但是,最重要的一點(diǎn)是,不具備預(yù)見能力的客戶可以通過反射檢測(cè)到C#屬性的存在。例如,只要相關(guān)對(duì)象屬性是真正的C#屬性,一個(gè)Datagrid對(duì)象就可以在一個(gè)ArrayList集合中顯示相關(guān)對(duì)象的屬性。</p><p>  在一個(gè)接口中,C#屬性的表示是依賴于語(yǔ)法的,因此在實(shí)現(xiàn)接口時(shí)會(huì)產(chǎn)生一些差異。我們應(yīng)該深入理解使用C#接口特征的相

101、關(guān)概念和使用細(xì)節(jié)。</p><p><b>  接口的細(xì)節(jié)</b></p><p>  C#接口的主要優(yōu)勢(shì)在于,接口把對(duì)象的交互進(jìn)行了限制。這種限制實(shí)際上是一種解放。就一個(gè)實(shí)現(xiàn)了某個(gè)接口的類而言,這個(gè)類可能在提供這個(gè)接口服務(wù)功能的過程中發(fā)生了許多變化,但是這些變化不會(huì)影響到這個(gè)類的客戶。雖然使用借口的目的很容易理解,但是在時(shí)間中,細(xì)節(jié)又迫使開發(fā)人員不斷地求助于參考資料

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 眾賞文庫(kù)僅提供信息存儲(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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論