I. Prerequisites 1. Proficient and Solid language Foundation
?? If you learn Java, but the reflection, generics, annotations have been semi-solution, or do not read what frame, go back to the Java Foundation to hit solid instead of you more beneficial.
2.UML capability
?? In software engineering, UML plays a very important role in the different life cycle stages of software, there is no good UML level, the face of large-scale project source will be helpless.
3. Understanding of the business
?? If you want to read the project business is relatively strong, prior to a certain understanding of the business is necessary.
4. Design Patterns, Refactoring mastery
?? There's nothing to say in programming languages or anything. Focus on one: Design patterns because the Android source code used in a variety of design patterns, if not design patterns, will greatly reduce your reading comprehension speed.
5. Deep understanding and understanding of coding specifications and conventions
?? Significant coding work, or projects under large, organized systems, will adopt a set of coding norms, guidelines or conventions. The goal is to enhance the reliability, legibility, and maintainability of your code.
?? Knowing this set of rules, perhaps a class name, a method name can help you understand the function of the whole class or method, or the conventional separation, will have a certain degree of support for your ideas.
6. Know what your purpose is
?? You read this code in order to solve the problem, not to read and read, where do you think it is excellent design?
Two. Total-Functional understanding
?? Learn about project features (Sample and documentation) and mainly into a few chunks. Also understand your needs, such as Pulltorefresh's pull-down implementation.
?? This code is designed to meet what needs, is to solve what problem? What are the pros and cons? Join to let you design to solve this problem, where will you start? What problems will you encounter? How will you solve these problems? Then look at the code to verify each other's learning.
1. You can think of yourself first if you will be how to achieve this project, perhaps see the source process will find the idea of collision.
2. If the time is tight, you can first Google some of the project-related documents combined with code to see, to help quickly grasp, but the online analysis of the article is uneven, need to be cautious.
Three. Total-Overall design
Keywords: hierarchical (hierarchical), common pattern correspondence, process and relationship, top-down, must find a good entry point, module, component
?? To understand a system, it is best to take a top-down approach. Try to capture the architecture of the system first, don't get into the details too early, because that's usually not helpful for you to know the whole picture. Reading code does not need to be read from the first line, and our goal is not to read through each piece of code.
?? When reading code, most will take the top down, cobwebs way. By recording layers of tree-like structure, the programmer can gradually establish the architecture of the system, and can be based on the granularity (granularity) needed to determine the level and sophistication of the deployment.
?? The importance of architecture over detail and premature drilling into details is not helpful for you to understand the whole picture.
?? It is not easy to understand the architecture of the system from the source code base of the system. However, after identifying important architectural elements, it is easier to navigate the entire system, understand the structure and properties of the system, and plan additions, modifications, and refactoring activities. This is because, once the architectural features of the system are extracted, we immediately share a set of semantically rich vocabularies with the system's creators. In addition, understanding of the system architecture can help us understand the types of interactions, communication patterns, and code structures.
1. Enter
Source code, other people's analysis documents
2. Tool 0 draw the overall diagram to clarify the logic
?? Use the process to comb (very important), that is, to see how to call First, and then follow the process of the call to walk.
?? Drawing class diagrams (which only focus on methods and classes) can be either primary or secondary, or they can be sketches that can help you quickly understand the internal code flow. Use the class diagram in UML to establish a static structure, and analyze the relationship between classes and classes.
?? Use case diagrams, class diagrams, Time series diagrams, and readily available drawings
?? When you look at the code side of the drawing, when you have all the code can be converted into a design, you must have enough knowledge of the code.
?? Drawing, a program for complex logic
?? The entire library is divided into which modules and the call relationship between the modules. For example, most picture caches are divided into modules such as Loader and Processer.
0 questions
1. How does the system initialize?
For the app, for the full app, it's Manifest to find the entry Activity, judging the Ingress class from the calling interface for the tool library. Then step into the IDE.
PS: Generally good open source project specifications are relatively good, classes, functions, variables from the name can understand the role, so if you need to quickly master the principle of the key to see the function can be.
2. What are the other systems (or users) that are connected to this system, and what are the boundaries of the phase?
3. How does the system react to various events?
4. How does the system handle various anomalies and errors?
0 experience in previous architectures
Design Patterns
?? Generally mature projects include a large number of design patterns and architectural ideas.
Schema mode
?? Large-scale software development efforts must use a suitable architecture to construct the system to be created and control its complexity. This architecture generally formulates the structure of the system, how it is handled, and how the various components of the system are decomposed in a modular manner. Large systems may also draw inspiration from frameworks, design patterns, and domain-specific architectures to reuse their architectural ideas.
On a larger scale, the code of a large system is often decomposed into object module libraries, reusable components, and even standalone integrations. You can also try to think about the project's architecture from the perspective of components, libraries, and modules.
Many of the systems we analyze follow a simple "main program and subroutine" structure. Other systems use more complex architectural constructs to organize their constituent subsystems. Common, important structures can be categorized into a few disparate architectural types: Centralized repository, data flow, object-facing, or hierarchical architecture. These schema types are often combined into a hierarchical structure to control the complexity of large systems. A system can show a variety of different architecture types at the same time, examine the same system in different ways, analyze different parts of the system, or use different levels of decomposition, all of which may find different schema types. This piece of books can read a little bit of architecture.
Element encapsulation: Components, modules, namespaces, objects, libraries.
0 hands-on notes
?? Here formally began the Code analysis, the analysis process if the brain can't remember, more hands down the main classes, functions and other roles
?? For frameworks, take a look at the list of APIs and find important APIs that interest you.
0 organization of the project
?? We can analyze how a project is organized by browsing the project's source tree-the hierarchical directory structure that contains the project sources. The source tree is often able to reflect the structure of the project on the architecture and software processes. Consider the source tree of the Apache Web server.
?? Don't be intimidated by the huge collection of source code, they are generally better organized than small, specialized projects. Although it looks very large, it is still easy to find the source code for a particular tool.
3. Output
General diagram, List of issues encountered and source reading notes
Four. Sub-detailed design: In-depth care details 1. Input
Source code, other people's analysis documents, clear the output of the schema
2. Tool 0 Positioning
?? Find the specific feature implementation modules you need to know. Tool methods can also be as above.
?? Quickly search by keyword to read the code of the part you need to see.
?? Once the target code is located, it is analyzed for him, ignoring other unrelated parts. This is a skill that must be mastered. If you feel that it is difficult to understand the code in the original context, copy it to a temporary file and delete all irrelevant parts. The formal name of this process is slicing.
Android, quickly locate the function of interest on the basis of find in path/find usages, more command + F page search, General basic positioning is difficult to escape our palms, the method is actually very simple. Https://drakeet.me/quickly-locate-the-function-code
0 Modify and run the code &debug
?? Sometimes the code you read may come from an environment that is completely unfamiliar to you (computer language, operating system, or API). Once you are familiar with programming and basic computer science concepts, in most cases you will be able to understand the basics of the new environment through source code. But pay attention to reading from a small program, and don't get caught up in a large-scale system study immediately. Compile the research program and run them. This allows you to get instant feedback on how your code is expected to work, and how you can get a sense of accomplishment. The next step is to actively modify the code to verify that your understanding of the code is correct, again, to start from a small change, gradually increase their scope. By actively intervening in real-world code, you can quickly learn some of the basics of the new environment. When you think you have mastered them, consider putting in some effort (and perhaps some money) to take a more organized approach to learning the environment. Read the relevant books, documents or manuals, or take a training course, both of which complement each other.
?? Another way to actively read existing code (as a document) is to improve it. Compared with other text works, the software code is a living artifact, they are always constantly improved. If the code is valuable to you or your community, consider how to improve it. may involve using a better design or algorithm, documenting some code, or adding functionality. The code in an open source project is often not well documented, so apply your understanding of the code to the improved documentation. When working on existing code, please coordinate with the author and maintenance staff to avoid duplication of effort or to create disgust. If your changes are stronger, consider applying to be a submitter of a concurrent version control system.
?? There are questions to run the program, or modify the run, to see the results and your expected consistency not to prove/negate your own ideas.
?? The stack frame clearly helps us to list the process of invoking the method, which is a very important tool for reading the source code.
0 Code Execution Process analysis (better with stack frame analysis)
?? The general reading of a code that is not written by itself is concerned with a piece of code, such as a process line. If this code makes you look dazzling, the most effective way to allow the condition is debug debugging. Follow-up debugging in step-by-step will allow you to understand the logic of the code in terms of the code's execution steps. If debug debugging is not possible, I will start from the most shallow layer of code, clear the idea, first not to focus on the deep logic or functions, need to use the time to carefully review.
?? When you are reading a piece of code, you may try to convert your position, from the perspective of the observer to the writer's mentality, to figure out the original author's psychology and situation. When you try to stand in his position and read through his way of thinking, tracking the code he writes, it will feel smoother.
?? Detailed analysis of the specific code required. Understand the meaning and correlation of variables, and understand the implementation of the logic and algorithms. Good code, the most needed comment here.
0 Repeat reading, note notes (especially English comments) plus Todo reading
?? Even if you read the code, you need to read it again, because there may be a lot of good design places missing, and many places may also understand mistakes
?? If you read the open source code, you will see that a piece of code, possibly more than half of the program code, is legal information and management information, such as copyright information, license information, and program version identifiers. Large, organized systems typically provide this information, while also summarizing the functions of specific programs or modules. This is the part that can be skipped directly.
0 Analysis of questioning method
?? Encountered somehow introduced, asked himself, why introduced, and then through this thing to see where he used the
0 draw Local Detail graph: Three kinds of graphs you can read any Android code.
ER diagram: The relationship of entity classes to complex data structures. Use the Grab Kit tool to help you analyze the types and correspondence of entities.
Page layout diagram: Layout structure comb look at the Android project in addition to the class diagram, the layout of the entire page structure is sometimes more important than the class diagram after all, Android is the front-end technology
Class diagram.
0 Focus, List of points of focus, depth & slice by point
?? It is difficult to understand all the imitations in a matter of a sudden. Can be divided into modules learning
?? When looking at a particular class, it is best to first identify the important components. In our case, the important component is global variables and important methods.
?? To understand the utility of a function, you can use the following strategy.
- Guess. Based on the name of the function
- Read the comment at the beginning of the function
- Analyze how to use the function
- Read the code of the function body
- Consult the external program documentation
?? Slicing: In deducing the details of a program structure, a valuable conceptual tool is slicing. Informally, you can consider a program piece as a program that can affect the value of a variable.
0 Piecemeal 3. Output
Local illustrations, problem lists and source reading notes
Five. Review
- Solve the problems you encounter in reading
- Go back and review what you did in the first few stages.
- Can you suggest improvement suggestions?
- A place of great design
Summarize into a document, preferably written as a blog, recommend a directory structure.
Project Introduction
Characteristics
Simple Usage (one demo)
Overall design
Class diagram
Process Analysis: Stack frame + timing diagram
Core Module Sub-statement
Reading comprehension & Advantages and disadvantages & Improvement opinions
Six. References
https://www.zhihu.com/question/19759722
Code reading methods and practices
SOURCE Reading Series: source Reading method