040. [Switch] For understanding framework

       Emergence of the concept of frameworks and libraries are all due to people's desire for reuse. "Do not reinvent the wheel", the software industry has become a classic saying. From the multiplexing function of the initial single source code to object-oriented class multiplexing (typically embodied in the form of library), and then based on the component programming binary components (the presence of IL .NET assembly is in the form of a) reuse, it is the level of abstraction of software reuse is increasing. Now, the frame multiplexing level of abstraction is another upgrade, not just the frame multiplexing function of multiplexing, it is designed for reuse.

The difference between 1.1 and framework class library

   We first take a brief talk about what is the library (Class Library)? The name suggests, the library is a collection of some of the classes, as long as we can reuse some of the classes focused into a Library, we can call it a library. There may be some correlation between the number of elements in the library (such as classes, structures, interfaces, enumerations, trust, etc.), but these associations are typically used to support a full expression of class interface concept or concepts. If we are from a higher perspective to look at the library, you may be found to be irrelevant or loose relationship between libraries in a "a complete concept."

   Then for the frame, the first frame is the meaning of a skeleton, which encapsulates the control logic within a processing flow of the art, we often say that a semifinished product is an application framework. Depending on the type field are so numerous, the framework must be targeted, for example, the underlying communication framework designed to address, a frame or special medical field. Framework also contains many elements, but the closeness of the relationship between these elements is much greater than the relationship between the library elements. All elements of the framework are to achieve a common goal and mutual cooperation.

   Not a universal framework can be applied to all kinds of fields and applications, targeted framework is very strong, it focuses on solving problems in a particular area, and is committed to provide a common solution for this particular area.

   The main difference between the frame and the library in the following aspects:
(1) from the structure, said internal frame is a high cohesion, while internal library is relatively loose.
(2) frame encapsulating process flow control logic, and the process does not involve any library almost flow and control logic.
   Since the frame is a process flow of the control logic is encapsulated, such that only the skeleton framework of an application. The process flow and control logic framework requires carefully designed, as all applications will use the frame multiplexes the design.
(3) having a frame IOC (Inversion of Control) capability, but no library.   
   IOC, commonly known as the Hollywood model (Do not call us, we will call you). For the library of elements, it is usually by our application to call it; and the frame having this ability - call our application logic at the appropriate time. This capability is through the framework extension points (or "slots") to do - specific applications into their own logic by extending the point, and at the appropriate time, the framework calls this extension point registered logic. In fact, .NET events (event) release, a representative example of the predetermined mechanism is the IOC.
(4) to focus on specific areas of the frame, but it is more general class library.
   Complete expression cassette focus on a particular area of the solution, but hardly library for any particular area. For example, communications framework mentioned in this book only if you need to build applications that communicate directly in the TCP / UDP basis, and regular expressions such as libraries, but can be used in a variety of different applications.
(5) frame is typically based on the number of libraries, the libraries are generally not dependent on a single frame.

General framework and application framework 1.2

      If you want to further classify the frame, the frame may according to the art for versatile and whether they are classified into a common framework (General Framework) and application framework (Application Framework). Generic framework can be used in different types of applications, the application framework is used only for a particular type of application.
      For example, the ORM frame NHibernate is a generic framework can be used for all types of applications need to address the O / R mapped. And a financial application framework is a framework, it is used only to finance the type of application.
      So to speak, the general framework to address is the "universal" problem with all types of applications are concerned, and the application framework to solve the problem is a particular type of application concerned. So, if we need some type of core application business logic flow to the next frame, the resulting framework is an application framework. Compared with the general framework, application framework need to know more domain knowledge in the field of business objectives.
      When implementing a specific application, can be applied by way of a plurality of common frame and frame combination, it is a good fast, high-quality application development. For example, an application of a financial sector, the financial framework can be used as an application framework to address issues related to financial business logic, data access using Nhibernate to solve, using ESFramework solve the communication between the application of each distributed system. 

      The following diagram describes the hierarchical relationship between the library, and the application framework.    Of course, an application may be completely without using any framework, but began to build from the bottom most basic API (such as the .NET Framework). For micro-systems, this approach may work. But for large-scale application complexity, degree of difficulty can imagine.
The difference between the frame and libraries


1.3 application framework in

   When a selected application framework, we need to do is add specific application logic framework in place to provide extension points, that is, the use of "blood" and "flesh" to fill the skeleton resulting in a "organism."
   Since the frame is usually after repeated use and tested in practice, so there is a certain guarantee of quality, which allows us to use less time and less code to achieve a more stable system possible. Of course, the framework is not a "silver bullet", it does not solve the fundamental problem of software complexity, but we pass it one step closer to the ultimate ideal goal.
   One thing to note, the framework allows us to have the support of the system at the same time, it also gives the limit. Because usually when we determine the use of a certain framework, we must limit within the framework of "the box" and to build our application. Most of the time, this is not a problem, but if because of limitations of the frame and seriously affected the time to achieve the goal of our system, we need to consider whether they should give up this framework, or a change other the same type of framework.

1.4 Design Framework

   Framework allows us to speed application development faster, higher quality, lower cost, these benefits are self-evident. However, faced with the myriad changes increasingly complex software requirements, design and implement a highly flexible framework for reusable easier said than done!
   Framework derived from the application, but higher than the application.
   Framework is often so produced: we have a lot of experience to develop certain types of applications, we summarize what this type of CCP, will refine it to a high level in order to prepare multiplexing. This "high-level" what is the prototype frame. As we continue to accumulate experience, the framework will continue to improve and develop.
   Framework is a product of practice, rather than theoretical research out of the laboratory. So the best way to design a framework that start from a specific application, in order to provide a common solution for the application of the same type as the goal, constantly refining the specific application, the extraction frame! This framework is then used in the application, and continually revise and improve the use of the process.
   One thing to note, as with all elements of software architecture design is a trade-off (a bit like the art in this area), the design framework is no exception, as mentioned earlier, provides a framework for the application of a skeleton, but also to our application delineation of a frame, we can only in this limited world to play. So, a good framework should be designed using a very appropriate trade-off decisions to the framework while providing strong support for our application, but for fewer restrictions on our application. On balance, never a simple matter, but there are a lot of experience in the design of the framework can be for our reference.

1.4.1 design experience framework, principles

(1) Do not use the framework to do too many assumptions!     

   Framework for the application to do too much on the assumption that the phenomenon is a very specific, pre-empt the framework, the application was originally going to do football over yourself. This is a typical thankless practice. Framework pre-empt, might make a specific application to develop a simple, but many more will want to apply the framework to increase the shackles and burdens of this is not necessary.

(2) using the interface, to ensure that all the important implementation framework is provided that can be replaced.

After all, not an application framework, so the framework can not consider the specific circumstances of all applications to ensure that all components are important implementation can be replaced, it is very important, it enables applications to replace in part based on the framework provided by the current situation the default implementation of the components. Use the interface to define the connection between the frame components and the individual components of the frame to increase reusability.

(3) framework should be concise, consistent, and the target concentration.

Framework should be simple, do not include those things did not matter to the target framework to ensure the presence of each component of the framework is to support the achievement of the goal frame. Too many unnecessary elements (classes, interfaces, enumerations, etc.), the framework will become difficult to understand, try to transfer these less important for the core objectives of the framework element to the library, you can make the frame more clearly, more targeted concentrated.

(4) providing a common framework, but do not fixed skeleton structure, the skeleton is also possible to make the assembly.

For example, if it is some kind of framework for business processes, then the framework should not only provide a set of business processes can not be changed, but the process flow should be "one-step" technology, so that each step can be re-assembled, so As a result, the application will be able to change the default frame processing flow according to the actual situation. This ability can be customized framework can greatly improve the framework of reusability.

(5) continuously reconstructed frame.

   If the design and implementation of a quality framework What is the secret? Only one answer, reconstruction, constantly remodeling. Reconstruction framework of the implementation code, and even the design of the reconstructed frame. Reconstruction of the driving force stems from several aspects, such as the nature of the problem to be solved with a clearer understanding of the preparation, we found that certain components responsibilities are not clear, hierarchical structure difficult to use, such as lack of clarity in the framework of using the framework of the time.

1.4.2 How to be regarded as a good framework?

      One of the main features of the framework is excellent: simple. This simplicity is not easy to get, as an excellent framework is not easy to achieve this simplicity framework needs to constantly spinning, continue to refine and improve. The simple reason is that it really captures the essence of the problem to be solved . A good frame typically has the following characteristics:

(1) a clear, concise and consistent.    

      "Clear" refers to the structure of the framework is clear, hierarchical framework is clear and bright, responsibilities framework of various classes and components are clear and unambiguous.

"Simple" refers to the elements that do not inconsequential excess framework, objectives and responsibilities of the various classes and components are very focused, which is reflected in the design principle of "high cohesion and low coupling."

"Unanimously" usually brings such benefits, users familiar with the frame after part of the frame, another part of the framework will be very easy to understand. "Matching" is generally reflected in the naming rules are identical, the named meaning, consistent with the way the assembly components and the like use.

(2) easy to use

      Only easy to use framework will go further.

   It is because of ease of use, users are possible framework to try this framework, it is possible to adopt this framework decision until after the trial satisfaction. A framework function even if more powerful, if difficult to use, so users are likely to frame simply do not have the idea to try this framework.

Framework vitality stems from the framework has continued to improve and develop, if no one uses this framework, which will be no development and improvement of the power source. As a user-friendly interface is an important part of the outstanding applications indispensable, easy to use it is an important characteristic of a good framework.

(3) highly scalable and flexible

      Framework to deal with the myriad changes of the application through highly scalable.

      No single framework can anticipate the needs of all applications, universal framework does not exist. Attempt to design and implement a universal framework idea is absurd. The framework must have the ability to "maintaining the status quo", the framework can do this by reserving the right to use, adequate extension points.

      Flexible framework embodied in the framework can be assembled and configured differently depending on the application, as the current framework is designed for custom applications like.

(4) lightweight

      "Lightweight," said the popular point is to only pay for services they want to use without having to pay for services you do not. A heavyweight framework there is a very obvious feature is that if you need a complete set of service packages, it is no problem, the frame can be very good to meet you; but if you only need this in a small package block dessert, I'm sorry, the framework will still impose a complete package to you, you have to pay the whole cost of a package.
   Excellent framework should support the principle of user "demand taken", the user can freely framework of "a la carte" assembled to meet their needs.

(5) weakly invasive

      The so-called "weak-invasive", using the application framework can be as much as possible a common way to write application logic, without having to adapt the framework had to use some special techniques.

   This may be a bit difficult to understand, we can give an example to illustrate simple. Two main ways in .NET, to achieve the AOP (aspect-oriented programming) and the mechanism is to use dynamic Proxy agent. Use AOP framework Proxy implementation usually requires those classes need to use AOP to intercept function must be inherited from ContexBoundObject; and the use AOP framework dynamic proxy implementation is nothing so intrusive request, we can still be the most common way to write application logic class, such framework will be implemented at runtime AOP interception proxy objects arranged according to dynamically generate the target object. So we can say that compared to using AOP framework for dynamic agent Proxy way to achieve AOP framework to achieve, with weaker invasive.

   Weak frame means invasive application logic less interference, since the application logic classes are regular class, which is very convenient application logic further multiplexed in a program, while another program may employ a completely different frame.

 

  Summary: An assembly is to increase the reusability of code, speed up development and design, with input and output processing functions of an event. In a relationship is called in the program, program developers to implement their own design for this function for the realization of a function by their own design logic, with inheriting a packaged tool type methods.

   The biggest difference is the framework for the realization of the framework is a full function and design, complete realization of the framework itself encapsulates the logic of this function, only you need to apply the framework to implement this feature in the program development. Program to do is apply it directly, only the application code and some open interface for custom replacement function can be realized.

In using the framework developed in the framework for the realization of a fully functional part of what needs to be called in the program so that the program needs to cooperate in the development of design framework, so that the frame is a shelf, just to fill the inside of the frame located on the program. The assembly is located under the program, it is to be called, often just deal with the problem, return the results.

  Framework program is set, but relatively general assembly, the framework is more advanced in the application package top.

A frame member is to design a reusable, which defines the architecture of the application, illustrates the entire design, dependencies between cooperating members, allocation of responsibilities, and the control flow, showing the cooperation between a set of abstract classes and examples the method, which provides a multiplexed context (context) relationship member. Libraries and frameworks are born to solve the reuse, and reuse libraries primarily on the settlement procedure code, mainly to resolve the frame design reuse solutions for reuse.

Original: http: //blog.sina.com.cn/s/blog_732ae613010155gj.html

Guess you like

Origin www.cnblogs.com/badboyh2o/p/11610303.html