Design Patterns in C #

来源:百度文库 编辑:神马文学网 时间:2024/04/27 15:57:11
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 AlexandeChristopher 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.
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.
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 objectBorrowReader(IDataReaderreader);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 :
Pricatestatic objectGetNames(IDataReaderreader)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.
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 interfaceIAdvertisementPublic interface IAdvertisement
{
IntGetID();Int GetID ();
StringGetADCopy();String GetADCopy ();
VoidSetADCopy(string text);Void SetADCopy (string text);
}
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.
Interface details
C # interface of the main advantages is that the interface of object interaction of the restrictions. 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.
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.