"C ++ Primer" reading note 6

zhaozj2021-02-16  67

Note: 2.3

As early as 2.1, the author will leave us a question: Do you want to become a C to need those conditions (practice 2.2)? Personally think this is very important. It is directly related to our direction of design ideas and efforts. It is clear that our direction should be: as much as possible to become a class of languages, in other words, in the design, for operators The support is more important than the average member function, and another consideration is to provide our continuation of the thinking of STL later, visible. If we use C as an oo language, it will not think so.

For beginners, I want to achieve a very good code in this section, it is almost unrealistic. In this section, our task is to understand design ideas, understand the basic structure of the class, learn to use pseudo code. Design a Class that meets the needs, the following is what I understand in this section.

The first step: Clear design needs, we can take a closer look, obviously, it is not perfect, but can meet the needs of the author, here we can feel the author's professional quality: User needs, our software often has such problems, hundreds of MB procedures, in fact, we can really use one percent, cost and resources have been wasted, as if you only meet designers Vanity

Step 2: Determine the data to be encapsulated, of course, we must first understand that the purpose of the package is to ensure the relative safety of the object data, to unintend the meaning of the package, such as:

Class a {

INT i

PUBLIC:

...};

Class b {

a s;

PUBLIC:

}

A few days ago, someone asked me like this. , Whether B can operate the data in S, the answer is: YES. But if you ask. . The data in S is available in B. The answer is that NO is that the data is only used by the Sish method for the packaged data. So how do b how to operate S? This will lead to the third step.

The third step is to design the public interface. Personally feel that interfaces and methods are different. The interface includes operators and methods, of course they have completed the function. However, there is a significant difference in the achievement of functions, and the operator considers the relationship between objects. The method considers the operation of the object itself. It is obvious that the former is more important for designing a data type, and for built-in arrays. We didn't consider its own things. But can anyone say that he is not a Class? But not we designed,

Next, talk about some habits, it may first look at the domestic textbooks will find it. Public written in this book before private. It seems that there is not much difference, in fact, we should find that if private members write the front keyword private, it is not conducive to the readability of the code, and we want to provide good habits and code style for our future cooperation. This is also one of the basic qualities of the programmer?

转载请注明原文地址:https://www.9cbs.com/read-16077.html

New Post(0)