logo资料库

c# 外文翻译(原文+翻译)c#设计模式.doc

第1页 / 共10页
第2页 / 共10页
第3页 / 共10页
第4页 / 共10页
第5页 / 共10页
第6页 / 共10页
第7页 / 共10页
第8页 / 共10页
资料共10页,剩余部分请下载后查看
A model is a program u
Chr
You might think that the co
Software devel
Abstract, a kind o
There are several design patt
If you do not
Design Patterns in C # A model is a program using such a program, we can complete certain 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 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 to find some common, effective solutions, using these programs, not in the circumstances to resolve the relevant issues, complete the work so as to achieve the purpose. Certain areas of regular employees in the field will have a habit of terminology These habits contribute to the terms of the work related personnel exchanges. Some models customary terms. The so-called model is able to complete some specific task and reach the goal of the mission off-the-shelf technology. With a habit of technology and related terms, some of this technology and modes documented, These records document from the customary terms to be standardized and made some effective technology has been widely disseminated. 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 Pattern 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. This Department has been able to make an impact in other areas, partly because the author has a unique purpose of the observation. You might think that the construction approach is aimed at "building design." But Alexander 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 model 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 exercise is very crucial, this requires philosophical thinking, also faced with unpredictable challenges. Software 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 software 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 comments, and then from the translation of choice for your help greatest books, and as your 2020. 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 through 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. Category 1 refers to the realization of the type of method to achieve code. C # language to improve the interface concept, so that it can be a separate structure, thereby interface (namely : an object 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 C # interface can achieve more than one type interface. 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, 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, Therefore, we first discuss the C # language interface. 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 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 callback method, then the commission could improve these mandates, and therefore C # Entrusted language is a very useful content. 1. Interface and abstract category Please indicate the C # language and abstract category of the three interfaces between different. In use, failed to provide a method of non-abstract category with an abstract interface is similar. However, we need to pay attention to the following points : A class can achieve any number of interfaces, but only up to an abstract category of sub-categories. An abstract class can include abstract, and an interface all methods in effect are abstract. An abstract class can declare and use variables, and not an interface. An abstract category of the visit Xiuchifu 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 (even allowed to use public visit Xiuchifu). An abstract class can be defined Constructors, and not an interface. 2. Interface with the commissioning Interface with the commissioning of comparison : Interface with the commissioning of the similarities is that they can have the desired definition of the function. We learn in the process of commissioning 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 the C # language commission is how to work. 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 of this type of commission. Commissioned no standard type of name, but it standardized the method parameter types and return types. We consider the following statement : Public delegate object BorrowReader ( IDataReader reader); This statement of the Declaration of a new type of commission. Commissioned by the name of the type BorrowReader. The statement said the commission 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 : Pricate static object GetNames (IDataReader reader) { //…
} GetNames () 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 : 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 inclusive 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 available to read on a database, called a BorrowReader commissioned example (that is, the above reader transmitted to the commission examples), then read this database as a resource for the release. C # interface can be an inclusive, C # attributes (property), and indexer. Interface can be a tolerant, inclusive but not commissioned. Why? We can simply gives the following explanation : Delegate keyword introduction of a new type, and the event keyword introduction of a new member. A statement standardized interfaces members, and not the type, time can be classified interface, which can not be classified as commissioned interface. And detailed explanation : 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 incident 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 as inclusive so that a certain category of a public member of the incident, a client interface types can be composed of the above examples that category. The incident is a kind of interface standard component, we have ample reason for the interface, including the incident. When entrusted to a single callback method, one based on interface design is equally effective. However, if the design needs 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 registration, this advantage is particularly prominent. Is a one time member, the member can make an object or class to give notice to the news. Understand the language C # commissioned may be difficult, 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 commissioned 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 worry, a lot of people are. But we should really seriously study commissioned by the C # is how to work. which is not only to understand how the application of the key, as well as understanding how the category of interactive key. 3. Interface and attributes C # language can be an excuse for standardized interface must provide the indexer or C # attributes. If your definition 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 attribute value, then you will need a standard C # attributes. Following is a statement of a code without the use of C # attributes interface, but the realization, the need for a targeting of the attributes of the visit. Public interface IAdvertisement { Int GetID (); String GetADCopy (); Void SetADCopy (string text); } The above code interface is Oozinoz system Showproperties part of the library. In simple terms, this meant to standardize the interface of two 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 foresee the reflection customers can detect the presence of C # attributes. For example, as long as the relevant attribute is the real target of C # attributes, a Datagrid object can be in one ArrayList pools showing relevant object attributes. In an interface, C # attributes expressed in the syntax is 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. 4. Interface details 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 certain 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, but in time, Also details of the development staff have been forced to resort to reference materials. Interface description of the types of interaction in the process of the expectations and do not 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 similar course, entrusted only to standardize the method of each method parameter and return types. Also commissioned type, it can not be an inclusive one interface commissioned and treat it as a member. However commissioned by the types of variables and marking the event keyword variables could happen in interface. Apart from the methods and events, but also inclusive interface for indexing 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 achieve 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 sense of the design of the core content, as well as several of the core design pattern. 5. General Interface can not provide the content C # interface can be used to simplify and strengthen the system design, of course, Sometimes the excuse that may be beyond the general interface definition and scope of use. If you want to make a kind of interface with a customer expectations interface adapter, the
adapter can be applied to model. If you want to set such a simple interface, then the model can be applied appearance. 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 use synthetic model. If you want to achieve an abstract for their separation, so that they can change independently, then can be applied to bridge mode. Each model is designed 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 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 solve this problem. 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 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 information provided by the rocket, However simulation program also defines the rocket's working methods. Under such circumstances, we will find that the existing class has provided customers the services they need, but not of the same name. At this time, we can apply Adapter mode. Adapter model is aimed at : if a customer needs to use a certain type of service, This service is the category with a different interfaces, then Adapter model can be used to provide a desired interface. Java programming language and the language differences between the lies : C # Language no way any possible Cook Up Some of the anomalies in a statement. Whether this is a good character? Please give your conclusions and related reasons. In a way other than the first statement of anomalies because : 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 pointer 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 with all the anomalies. Developer statement requested some type of anomaly is not a substitute for such exception handling strategy. The other : programmers should be all they can receive help. Indeed, an application architecture should 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 file 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 terminology might happen some unusual statement from the method in addition to the first. In fact, this program is pouring out the water at the same time, the children are thrown out of. Object-oriented program 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 category could include other reusable kind of behavior effectively together.
C#设计模式 一个模式是一种方案,利用这种方案,我们可以完成某项工作。一个模式也是一种途径, 通过这种途径,我们可以达到某个目的。同时,一个模式也是一种技术。为了完成某项工作, 我们必须获取并利用有效的技术。这种思想可以应用于多种工作,例如:做饭、制造烟火、 开发软件以及其他工作。如果某乡工作所属的领域正在不段的完善,那么,这个领域的从业 人员会去寻找一些通用的、有效的解决方案,利用这些方案,在不用的环境下解决相关问题, 从而达到完成工作的目的。某个领域的从业人员经常会产生该领域的习惯用语,这些习惯用 语有助于相关人员对工作进行交流。模式也是一些习惯用语。所谓模式,就是一些能够完成 特定任务并达到任务目标的现成技术。随着某项技术及相关习惯用语的发展,一些人将这项 技术及模式记录成文,这些记录下来的文献使习惯用语得到标准化,并使一些行之有效的技 术得到了广泛传播。 Christopher Alexander 就是把某种技巧的最佳事实方案旧路为模式的先驱者之一。他 的研究领域是建筑学,而不是软件。在其著作《A Pattern Language:Towns,Buildings, Construction》一书中,Alexander 提出了建造房屋和建设城市的成功模式。Alexander 的 著作影响深远,因此也影响到软件领域。这部著作之所以能够影响到其他领域,部分也是因 为作者对目的具有独特的观察方式。 你可能会认为,建筑模式的目的就是“设计建筑”。但是 Alexander 明确提出,应用建 筑模式的目的是服务于那些以后要居住在这些建筑物内或居住在这些城市中的人们,并使他 们感到舒适和欣慰。Alexander 的工作表明,模式是一种获取并交流某个技术领域知识的极 好途径。同时他也指出,合理地认识并记录某项工作的目的是非常关键的,这需要哲学的思 考,同时还面临着难以捉摸的挑战。 软件开发群体已经对模式产生了共鸣,并出版了大量著作来记录软件开发的模式。这些 书籍记录了软件过程的最佳时间、高级体系结构,以及软件在类级别的设计,同时,与模式 有关的新书还在不断出版。如果你需要选择译本有关模式的书籍,你应该首先花一些时间去 读一读那些对已出版书记的评论,然后,从中选择译本对你帮助最大的书籍,并将其作为你 的学习对象。 抽象的说,一个类的接口是由这个类的某些方法和字段构成的一个集合。其他类的对象 实例可以通过这个集合对这个类进行访问。借口通常表达了方法执行的操作所提供的功能职 责,这些职责往往用方法的名称、代码注释,以及其他文档进行描述说明。一个类的实现指 的是在类方法中实现的代码。 C#语言改进了接口的概念,使之可以单独进行构造,从而把接口(即:一个对象必须做 什么)和实现(即:一个对象如何满足其功能职责)有效地区分开来。C#语言的接口允许多 个类提供同一个功能,同时,C#的接口也可以使一个类实现多个接口。 有好几个设计模式可以利用 C#所提供的特征。例如:我们可以用一个接口来适配某个
类的接口,这实际是通过应用适配器模式来满足一个客户的需求。为了讨论某些无法用 C# 语言完成的工作,我们应该了解 C#语言是如何完成工作的,所以我们首先讨论 C#语言的接 口。 如果你确实无法使用接口,那么,你可以使用抽象类(C++语言提供了抽象类)。然而, 在 n 层(n-tier)软件开发和对象定义构造等方面,接口具有关键的作用。与此类似的是, 如果你确实无法使用委托,那么你可以使用接口。如果某个公共任务需要注册一个方法来进 行回调,那么,委托可以改进这类任务,因此,C#语言提供的委托是一项非常有用的内容。 1. 接口与抽象类 请指出 C#语言的抽象类与接口之间的三种不同之处。 在使用上,一个没有提供非抽象方法的抽象类与一个接口是类似的。然而,我们需要注 意以下几点: 一个类可以实现任意多个接口,但是最多只能对一个抽象类进行子类化。 一个抽象类可以包括非抽象方法,而一个接口的所有方法在效果上都是抽象的。 一个抽象类可以声明并使用变量,而一个接口不能。 一个抽象类中的方法的访问修饰符可以是 public、internal、protected、protected internal 或者是 private,而接口成员的访问修饰符在默认情况下都是 public,而且,在 声明接口成员时,不允许使用访问修饰符(甚至不允许使用 public 访问修饰符)。 一个抽象类可以定义构造函数,而一个接口不能。 2. 接口与委托 接口与委托的比较: 接口与委托的相似之处在于它们都可以定义我们所期望的功能。我们在学习使用委托的 过程中经常会产生一些混乱,究其原因,部分是由于“委托”这个词,它可以表达含义具有 微小差别的不同概念。在对委托和接口进行比较之前,我们有必要回顾一下委托在 C#语言 中是如何工作的。 C#语言的关键字 delegate 引入了一种新的委托类型,这种新的委托类型可以确定什么 类型的方法才可以用于实例化这种委托类型。委托类型没有规范方法的名称,但是它规范了 方法的参数类型和返回类型。 我们考虑以下声明: Public delegate object BorrowReader(IDataReader reader); 这条语句声明了一个新的委托类型。委托类型的名称是 BorrowReader。声明指出该委 托类型可以用任何方法进行实例化,只要这个方法接收一个 IDataReader 对象作为方法参 数,并且方法返回类型为 object。假定某个类中有以下方法: Pricate static object GetNames(IDataReader reader) {
//… } GetNames()方法的参数类型和返回类型满足 BorrowReader 委托类型的规范定义,因此 可以使用这个方法名称对委托类型进行实例化,实例化语句如下: 变量 b 是一个 BorrowReader 委托类型的实例。任何能够访问该委托实例的代码都可以 调用对象 b,然后委托实例将调用对象 b 包容的方法。之所以使用对象实例 b,是因为这个 方案具有以下优点:其他方法可以在合适的时候调用对象 b 及其包容的方法。例如:一个数 据服务类可以获得一个数据库读取器,调用一个 BorrowReader 委托实例(即把上述读取器 传递给这个委托实例),然后把这个数据库读取器作为一个资源进行释放。 一个 C#接口可以包容方法、C#属性(property),以及索引器。一个接口也可以包容时 间,但是不能包容委托。为什么? 我们可以简单地给出以下解释: Delegate 关键字引入了一个新的类型,而 event 关键字引入了一个新的成员。一个接 口声明规范了成员,而不是类型,因此时间可以归入接口,而委托不能归入接口。 而详细的解释是: Event 关键字声明了一个特定类型的字段(一个“事件”),规范了其类型(必须是一个 委托类型)及其名称。C#限制了对事件的访问,客户不能使用事件类型(其委托类型)的所 有行为。客户只能使用委托所提供的+=和-=行为。这种限制所产生的结果之一是:只有声明 类可以调用(或激发)一个事件。但是,只要使某个类包容一个 public 事件成员,一个接 口客户的组成类就可以实例化上述那个类。因为事件是一个类的接口的标准组成部分,因此 我们有充分的理由让接口包括事件。 当采用委托对单个方法进行回调时,一个基于接口的设计是同样有效的。但是如果设计 中需要使用委托来持有并调用多哥方法时,那么,采用委托更为清晰。特别是当一个对象使 用一个委托让多个客户对一个事件(例如“点击”事件)进行注册的时候,这个优点尤其突 出。一个时间是一个成员,这个成员可以使一个对象或者类提供通知消息。 理解 C#语言的委托可能非常困难,特别是因为我们重复定义了“委托”这个术语的意 义。例如,我们可以使用“委托”这个术语表示一个委托声明、委托类型,甚至一个委托实 例。特别是,人们经常说“调用一个委托”,但是一个对象只能调用一个委托的实例,而不 能调用一个委托的类型。如果你感觉这部分内容有些混乱难解,别担心,很多人都是如此。 但是我们确实应该认真研究在 C#中委托是如何工作的,因为这不仅是理解应用程序如何工 作的关键,也是理解类之间如何进行交互的关键。 3. 接口与属性 C#语言的借口可以规范接口实现必须提供的索引器或者 C#属性。如果你定义了一个新 的集合类型,那么就需要规范一个索引器。如果你做出了以下声明,即某个实现中必须包括
分享到:
收藏