Chapter 4 Interfaces

Source: Internet
Author: User
Chapter 4 Interfaces

The software is composed of different functional modules. Different parts are independent of each other and affect each other. Therefore, in the software system, ensuring the independence of each part and making mutually error-free calls becomes a conflict.

To ensure the independence of all parts of the system, high cohesion and low coupling are the basic principles that must be followed in system design. The requirements of high cohesion and low coupling are not only the requirements between the horizontal modules, but also the principles that must be followed by the design between the vertical layers of the system. The system hierarchy design issues will be discussed in the later part of the application software system architecture.

At the same time, in order to ensure that each part can call each other without errors, a series of rules must be formulated for the call. These rules are interfaces. Therefore, the interface mentioned here is not the meaning of the interface syntax in the program language, but a broad concept.

Essentially, an interface is a contract that specifies the interaction between the real-time provider (Service Provider) and the caller (customer) of an interface. The introduction of interfaces brings great flexibility to the system design. You can see wonderful interfaces in the fields of objects, modules, and design patterns. It can be exaggerated to say that interface technology is the soul of object-oriented design.

"Interface-oriented programming, not implementation-oriented programming" 2. In order to make the software architecture more reasonable, as well as for the cooperation between teams, as well as the smooth development of software development, the first work of software design, the call interface is developed for the horizontal and vertical parts of the software.

An interface signs a contract between the service provider and the user to encapsulate the specific implementation of the service and provide the stability of function calling while ensuring the independence of both parties. When the software is modified, upgraded, or changed, both parties can change independently. However, this contract cannot be changed, which is a guarantee of software stability.

"Interface-oriented programming, not implementation-oriented programming" 2. In order to make the software architecture more reasonable, as well as for the cooperation between teams, as well as the smooth development of software development, the first work of software design, the call interface is developed for the horizontal and vertical parts of the software.

Note that when we design a database-based application system, when two modules need to interact, we should avoid using the method of directly carrying data in the database, instead, call the interface method defined by the module in the program. Otherwise, any modification to the database will cause a nightmare. Call the interface method instead of directly manipulating the database.

Here is a specific example:

This is an example of BBS. To clearly illustrate the problem, we should simplify the problem as much as possible. Now this system has two components: user login information maintenance and forum posting.

We can divide this system into two modules: UserSystem and ArticleSystem.

UserSystem will include the following features:

L New User Registration

L modify user information

L User Logon

Therefore, the UserSystem function can be represented as follows in code:

Public class UserSystem

{

Public void CreateNewAccount (Account acount)

Public void UpdateAccount (Account acount)

Public bool Login (Account acount)

}

The ArticleSystem function is simple, that is, posting. The code can be as follows:

Public class ArticleSystem

{

Public void CreateNewArticle (Article article)

}

When sending a post, you need to know the current poster and use the user information in UserSystem. Therefore, UserSystem must provide this access interface. We add an attribute in UserSystem:

Public static Account GetCurrentLogAccount {}

This GetCurrentLogAccount is the access interface provided by UserSystem for ArticleSystem. ArticleSystem does not need to know the specific implementation method of GetCurrentLogAccount. He only needs to know that when he needs to use the user login information, he can call this method. In the future, no matter how UserSystem changes or even changes the Account table design in the database, as long as the call interface GetCurrentLogAccount remains unchanged, ArticleSystem will not be affected. Note: Do not directly select the Account table of usersystem in ArticleSystem.

The above interface is a generalized interface concept. As for the wonderful use of language interfaces, there are almost everywhere in design patterns.

The above is the horizontal interface of the application system. Next, let's look at the problem of the vertical interface of the system.

The system level issues will be discussed in detail later. Here, we will give a brief description to illustrate the issues.

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.