Chapter 1 Evolution of Objects
I. Interpretation of polymorphism: When processing the type hierarchy, programmers often want to see objects as a particular type of member, and regard it as a basic type member, so you can write not dependent on special types. Code. In the form example, the function can operate the general form without concern that it is a circle, a square or a triangle. All the shapes can be drawn, erased, and move, so these functions can simply send messages to a body object without considering how this object handles this message. In this way, the newly added type does not affect the original code, which is the most common method of expanding the object-oriented program to handle new situations.
Second, the operation concept: OOP program is like what a well-written C program is generally more simple and easy to understand than the same function. Programmers only see some of the definitions of the problem space object (instead of a computer), send it to these objects. These messages represent activities in this space. One of the advantages of object-oriented programming is to understand the code through reading.
Third, five stages of the object design
Here is a description, not a method. It is simply the observation results of the designs of the object. 1) Objects found this stage to appear during the initial analysis of the program. You can find objects by looking for external factors and element replica and minimum concept cells in the system. If there is already a set of libraries, some objects are obvious. The commonality between the class (suggesting the base class and inheritance), can appear immediately or in the later stage of the design process. 2) Object Assembly We find some new members when establishing an object, and these new members have not appeared during the object discovery period. This internal need for an object may use a new class to support it. 3) The system constructs more requirements for the object may appear in the later stage. With continuous learning, we will improve our objects. The need to communicate and interconnect other objects in the system may change the existing class or require new classes. 4) The system expands that when we add new performance to the system, it may be found that our previous design is not easy to support the system expansion. At this time, we can re-construct part of the system and it is likely to add new categories. 5) Object Reuse This is a true key test for classes. If some people try to reuse it in a new situation, they will find some shortcomings. When we modify a class to accommodate an update, the general principle of classes will become more clear until we have a truly reusable object.
4. Object development principles In these phases, some of the principles needed to consider development classes: 1) Let a special problem generate a class and then make this class grow and mature when solving other problems. 2) Remember, find the required class, is the main content of the design system. If there are already those classes, this project is not difficult. 3) Don't force yourself that you know everything at the beginning, you should continue to learn. 4) Start programming, allowing some to run so that you can prove or refute the generated design. Don't be afraid of the procedure of the process language style, the class segmentation can control them. The bad class does not destroy the class. 5) Try to remain simple. The less clear object with obvious use is better than a very complex interface.
Chapter 2 Data Abstraction
First, the importance of the library
Library, simply, some people have written code, package them together in some way. Typically, the smallest package is one or more header files with an extension such as L i B, and one or more header files in the compiler declaration library. The connector knows how to search and extract the corresponding compiled code in the L i b file. However, this is just a way to provide a library. On platforms across multiple architectures, such as u n i x, typically, the most sensible way to provide libraries is to use source code, so it can be recompiled on a new target. And in Microsoft Wi N D O W s, dynamic connection library is the most sensible method, which makes we can use the newly released D d L frequently modify our procedure, and our library function vendor may have sent us new D d L to us. Therefore, the library is probably the most important way to improve efficiency. One of the main design objectives of C is to make the library easy to use. This means that there is difficult to use the library in C. I know that this is a preliminary understanding of C design, so that I have a more in-depth understanding of how to use it. Second, statement and definition
"Statement" introduces the name to the computer, it said, "What is this name meant." And "Definition" allocates storage space for this name. The meaning of the function is the same regardless of the variable. In any case, both the compiler allocates the storage space in "definition". For variables, the compiler determines how many storage units are present, and the space is placed in memory. For functions, compilers generate code, and allocate storage spaces. There is a pointer generated by a function name that does not have a parameter table or a address operator.
Third, some functions:
1, Memcpy (): One byte one byte copy this variable, the first parameter is the destination address of Memcpy () starts the copy byte, the second and third parameters are the start address of the copy variable and the required The number of bytes copied.
2, realloc (): The stored unit header address that has been allocated and hoped, as its first parameter (if this parameter is zero, Realloc () assigns a new block), the second parameter is this new block The length, if this length is smaller than the original, this block will not copy, simply tell the relic of the relic of the manager is idle. If this length is much larger than the original, there is not enough space in the heap, so you have to assign new blocks and copy memory.
3, void * malloc (size_t size): The malloc function allocates a memory block of at least size bytes The block may be larger than size bytes because of space required for alignment and maintenance information.!
Fourth, dynamic storage allocation
The dynamic memory allocation function is part of a standard C library, including malloc (), Calloc (), Realloc (), and Free (). The C-heap manager is quite important, it gives a memory block, recovered them when using Free (). There is no tool for the pile, and you can provide a larger idle block if you can merge. If the program multiplely allocates and releases the stack storage, it will eventually cause this stack to have a lot of idle blocks, but there is not enough and continuous space to meet our needs for memory allocation. However, if the memory block is moved with a heap of merger, it will make the pointer save the corresponding value.
5. Compiling each unit -> Connect each target file
1) Each independent C file is a processing unit. That is, the compiler runs separately on each processing unit, while the compiler only knows this unit at runtime. This way, providing information with the header file is quite important because it provides the compiler with an understanding of other parts of the program. The statement in the header file is particularly important, because if you include this header file, the compiler knows what to do. For example, if Void fooat is declared in a header file, the compiler will know if we call it with an integer parameter, which will automatically turn the I n t into F L O a t. If there is no declaration, this compiler will simply speculate that there is a function that exists without this shift. 2) The compiler creates a target file with extensions .o or .Obj or similar names. These target files must be connected to the executable with the connector to connect these object files. During the connection, all external references must determine the corresponding actual address, replace these external references with these addresses.
Six, head file form:
In C , the use of the header file is very clear. They are forced for each program, which is placed in very special information: declaration. The header file tells the compiler which is available in our library. Because the library can be used without source code for the C P P file (only the object file or library file), the header file is the only place where the storage interface specification is stored. The header file is a contract between the developer of the library and its user. It said: "What is described here is what library can do." It doesn't say how to do it, because how to store in a C P P file, developers do not need to distribute these descriptions "How to do" source code to users. In order to properly organize code and write effective header files, there must be some problems. The first question is to put it in the header file. The basic rules are "only statements", that is, for the compiler only some information is required to generate code or create variable allocation memory. Because, in a project, the header file may be included in several processing units, and if the memory allocation is more than one place, the connector generates multiple definition errors. This rule is not very strict. If a "static file" is defined in the header file (visible only within the file), there will be multiple instances of this data in this project, and the compiler will not report an error. Basically, do not do confusion when they do in the header file. (Also see Effective C )
Seven, Nesting Structure: Simply use the range breakdown operator twice to indicate the name of this nested Struct. Stack :: link :: initialize () function Take parameters and assign the parameters to its members.