Abstract and specific

Source: Internet
Author: User

Abstract and specific

What is abstraction? First, you do not need to clarify what is abstraction. From what is abstraction, stable and high-level ones represent abstraction. Just like a company, it is best to ensure the stability of the senior management to ensure global development. During system design, stable abstract interfaces and high-level logic also represent the stability and flexibility of the entire system. A nest of soldiers is raging, and the construction of software is also like a war. Good design is from top to bottom. For specific programming practices, interfaces and abstract classes represent language-level abstraction.

The analysis of the concept of tracing is one by one. First, it depends on the specific concept, as shown in 3-3.

Therefore, in order to separate this tight coupling, the best way is to isolate, introduce the middle layer to separate changes, and ensure the stability of the middle layer itself. Therefore, the abstract middle layer is the best choice (as shown in 3-4 ).

For example, the most common server logic is as follows:

Public interface iuserservice

{

}

 

Public class userservice: iuserservice

{

}

If the dependency is specific:

Public class usermanager

{

Private userservice service = NULL;

}

Or dependent on Abstraction:

Public class usermanager

{

Private iuserservice service = NULL;

}

The difference between the two lies in the introduction of the iuserservice interface, which weakens the dependency of usermanager on userservice. However, the dependency method is not the only one. The intelligence in the design mode decouples dependencies through various programming techniques, which deserves attention and learning, later, we will discuss the design pattern.

Readers familiar with WCF can easily see that this implementation method is similar to the Recommendation mode of WCF and is also the basic idea of contract programming. We will discuss the relevant content of WCF and SOA in the following article.

To sum up, what is abstraction and what is concrete? In the author's opinion, abstraction is the strategic logic of the system's encapsulation of changes. It reflects the inevitability and stability of the system and can be reused and overwritten by specific layers; specifically, it includes the logic related to the specific implementation, reflecting the dynamic and changing nature of the system. Therefore, abstraction is stable, but specific changes.

Uncle Bob bluntly stated in Agile principles, patterns, and practices that all dependencies in the program should end with abstract classes or interfaces, which is a responsive response to abstract programming, the root cause is the cognition and decomposition of abstraction and specifics: Association should end with abstraction, rather than being specific, ensuring the stability of system dependencies. Modifications to specific classes do not affect other modules or relationships. So how to achieve this kind of ideal relies on abstract design?

Clear Layers

Simplifying complex problems is the universal wisdom of human thinking, and naturally is the basic idea of implementing software design. Abstract complex business needs through the modeling process, refine them, and save them as authentic. One of the goals of an abstract process is to form a simple process for handling complex problems. Only by forming a simple logic at a level can we sort out the relationships in complex requirements clearly, as mentioned above, isn't dependency processing?

Therefore, a clear hierarchy and modular formation are the only way to achieve system abstraction.

Decentralization and centralization

The design process based on requirements is a decentralized and centralized process, which organizes the business related to requirements through the demand analysis process of the development process, the basic processes such as Requirement Specification Description, outline design, and detailed design are gradually formed. Decentralization and centralization is a process of organizing requirements to form a design. Therefore, it is an important analysis process and means to grasp the abstraction and specifics in the system. Modern software engineering has formed a scientific standardized process processing logic. For example, we can use UML to design processes more clearly and analyze design elements for standardized communication and communication.

Concrete Abstraction

Abstract specific problems into the main points of attention in this section. What is the solution? The answer lies in the design mode. The design mode is the summary and practice of the wisdom of the predecessors. Therefore, familiarizing yourself with and learning the design mode is the only way to learn and practice design problems. However, no problem is solved by the design model, and no model can adapt to all problems. Therefore, we must try to accumulate more models to cope with changing needs. As the most important topic in software design, attention models and practice models are the records of growth.

Encapsulation changes

In general, abstraction and change are like a pair of twins, which isolate specific change points and encapsulate them in an abstract way. Finding abstraction in the place of change is the most ideal way to face abstraction. Therefore, how to look for changes is the primary issue to be solved in design. For example, the goal of the factory mode is to encapsulate changes in object creation, and the bridging mode focuses on changes in dependencies between objects. The 23 classic design models, from a certain perspective, are the different solutions proposed for the encapsulation of different change points.

This design principle is also known as the SOC (separation of concerns) principle, which defines a unified rule for achieving the ideal high coupling and low cohesion goals.

3. Design Philosophy

The reason why I spent so much time talking about a seemingly simple problem is that the final ideal is to return to the proposition of the software design goal. After careful research, we can find that the last part of the design is to deal with the relationship, just as the significance of life lies in adapting to society. Therefore, we can see from the perspective of design goals that a perfect design process is the process of dealing with relationships, that is, the process of organizing dependencies, and finally form a reasonable coupling result.

Therefore, object orientation is not mysterious, especially from the perspective of life. The depth of object orientation can be summarized:

Goals: reuse, scalability, and compatibility.

Core: low coupling and high cohesion.

Means: encapsulate changes.

Idea: For interface programming, for abstract programming, for service programming.

In fact, it is so simple. In this sense, object-oriented thinking is the foundation of modern software architecture design. The following uses a three-tier architecture design as an example to further understand the application of this dependency philosophy in a specific software system. The basic idea of dependency abstraction and isolation of changes is also an important basis for implementing a typical three-layer architecture or multi-layer architecture. Only when the layers depend on more stable interfaces can the changes between the layers be isolated within the layer without affecting other layers, this fully complies with the excellent design philosophy pursued by the open and closed principle. This idea can be expressed as a design in the form shown in 3-5.

 

As shown in figure 3-5, idataprovider serves as the abstraction of the isolated business layer and data layer, and iservice serves as the abstraction of the isolated business layer and performance layer, ensuring the relative stability and encapsulation of each layer. The design logic embodied here is exactly the embodiment of the basic concepts of abstraction and coupling. For example, as a reusable unit, abstract isolation ensures the uniformity and stability of the external publishing interface, therefore, the maximum reuse is achieved. By introducing stable interfaces in the middle, effective isolation at different levels is achieved, and mild coupling is reflected between layers, the business layer only holds idataprovider to obtain all services on the data layer, and the performance layer is the same. Finally, this method clearly implements the classic concept of interface-oriented and abstract-oriented programming.

By the same principle, many concepts of architecture design can be expanded to serve as a reference for service-oriented design. To put it small, this is the basic idea of the dependency inversion principle of repeated downadjustment in class design. Therefore, keep in mind the saying of a software engineer: any problems in software design can be solved by introducing intermediate logic. This intermediate logic is often encapsulated as abstract, and is the most reasonable and intelligent solution.

Let us once again praise Lao Tzu's theory of little country and people, to review how to achieve better harmony and unity in dependency philosophy and how to abide by the scientific software management ideology: the neighbors look at each other and hear each other from each other, the masses are always dead and busy.

 

This article is excerpted from the book ". Net (version 2nd) You must know ".

Book details: http://blog.csdn.net/broadview2006/article/details/6673353

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.