What is parnas principles?

Source: Internet
Author: User

Introduction to programming (Java)-1.3 separation of interfaces and Implementations

The parnas principle is calledSeparation of interfaces and implementation).

I. Excerpt [P100 -]:

1. Brooks vs. David parnas

How to organize multiple programmers in a large team in large-scale programmingSimultaneous development, Especially how to treat the code of other programmers, frederickp. brooks Jr introduced his practice at the time (around 1964) in The Mythical man-month: he decided that "all programmers should understand all the materials ", because "exposing all work to everyone's gaze can help quality control, which is due to the stress of other people's excellent work and the direct discovery of defects and bugs by their peers ". In this way, each project member has a copy of about 10,000 pages of the project work manual. In the face of a huge ibm OS/360 software project, Brooks believes that independent programmers cannot effectively work in parallel. Brooks said: nine women cannot produce a baby within a month, for the sake of conceptual integrity, the concept of human hands and time can be replaced is simply a myth.

David parnas, one of the founders of modern computer science and software engineeringIt is deemed that synchronous development is feasible! The only premise is to regard the subroutine/methodAbstract tools), Or the module called by parnas. When using this tool, you do not need to know its internal implementation.

In daily life, people are used to abstract tools. For example, when you use a TV, you do not need to understand the internal structure of the TV, such as the cathode ray tube and control circuit; the only thing you need to learn is to read the product manual, understand various buttons on the TV, various plug-in holes on the back, and various operations on the remote control. These are what TV users need to know.Interface or interface.

 

2. parnas principles

Parnas points out: (module) interfaces are basically composed of subprogram names and parameter names and types.

Module development should follow the parnas principles:

2. The module developer must obtain all the information required to complete the responsibilities of the module. In addition, no additional information is required.

2. The module developer must provide the target user with all the information required to correctly use the module. In addition, no additional information is required.

The previous article describes the principles that users of interfaces should follow. When developing a module, they only need to know the interfaces of other modules. The next article describes the principles that developers of interfaces should follow. Assume that a programmer has compiled the method Foo (). Generally, a programmer who uses Foo () is called foo ().User)Or a user programmer, and the program that calls Foo () is calledCustomer (clinet)Or customer program.

From the perspective of a client program, an interface refers to the signature and return value type of a method. From the perspective of a user programmer, an interface is all the information that the user needs to know when using this method, includingMethod header (method prototype) and important instructions. WhileImplementation)It refers to the code block that fulfills the function commitment of this interface, that is, the method body. In this case, the subprogram is used as an abstract tool by the user. You only need to understand its interface. The parnas principle is calledSeparation of interfaces and implementation).

★Users only need to understand the interface-parnas principles.

Ii. Description

In China's programming teaching, few people discuss/introduce parnas principles (interface and implementation separation), which is really surprising. Featured here in cc2001 (see the appendix B Table B-3:

Pl6. object-oriented programming Object-Oriented Programming
Separation of behavior and implementation separation of behavior and implementation


To this end,

  • Yqj2065 specifically added the following in the image about parnas: "The parnas principle proposed by him in 1972 or the separation of interfaces and implementations (separation of interfaces and implementation) isNone of the most important principles in software engineering. The parnas principle lays the foundation for object-oriented software development ."
  • Last semester lecturesC LanguageThe parnas principles (separation of interfaces and implementations) are explained during function introduction ).

The parnas principle does not force the source code to be black box. For example, JDK users can view the source code of all JDK classes (which is helpful for learning programming ). However, when using string, you usually need to check the jdk doc instead of the source code. Because interfaces and implementations are separated. The parnas principles indicate that user programmers can/should also turn a blind eye to the implementation of methods ". Note: When you understand the parnas principles (interface and implementation separation,Do not involve protection of intellectual property rights or code.

Following the parnas principle or the separation of interfaces and implementations,As long as the interface remains unchanged, the Method developer can modify its implementation without worrying about the impact of this modification on the customer program.. For example, in the early development phase of the system, a straightforward (brute-force) implementation is provided to simplify development, and the customer program does not need to be changed when the algorithm is changed to a faster implementation later in development. (Note: do not involve the OCP/Open/closed principle when discussing the parnas principles)

The parnas principle is the most important principle in software engineering. The reason why we use it as the three principles of object-oriented is that "this principle is widely applied in a series of object technology applications, the parnas principle is the core of functional abstraction and the underlying basis for data abstraction and encapsulation.


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.