Refactoring Reading Notes (Traditional)

zhaozj2021-02-17  33

From: "Areca_chen.tw" date: tue apr 16, 2002 3:31 PMSUBJECT: REFAACTORING Note -1

Refine definition of reforming Reform: Reform is a process of changing the system of software, which is the internal structure of the program code without changing the external behavior of the program code. This is a discipline to clean up program code to reduce opportunities to produce bugs. In essence, you are the design of the composed code when you refine. The general development process is to have a good design before you can have a good program. However, as the growth of the system is modified by the demand, and the program code will be modified, the original design cannot cooperate with the system's demand, and the design and program code is gradually detached, and the general system development is limited Time and manpower, unable to maintain design files and program synchronization, the original design file turns into a place where the original design file is used in subsequent development or maintenance. Due to the relationship of changes, the prite code that is considered a good design is not meaningful. Therefore, how to maintain these programs after writing program is still a good design is very important. Reform is a technique that gradually develops from this two difficulties. And both your original design is not good, the relative program code has no way to write very structural. At this point, you can use a reforming technology that you can also make the codes vary very structally. Each step of reforming is not easy. You just move some fields in the category, pull out some prior codes in the method, or move the program or down in the inherited hierarchy. Only these simple steps can change the design of the program code. The reorganization has also produced significant changes for traditional development methods. You no longer need to have a complete system design at the beginning, but a constant design in the development process. This makes your system constantly improved.

------------------------------------------ from: "Areca_chen.tw ""

The most important system of a poor design is not easy to change. The reason is that you can't point out what needs to be changed. When you don't know what is needed, there is a big chance to hide the mistake and causing a bug. For example, your output is a general file file. When you need to output an HTML format, your system does not have this flexibility, and adding an HTML format will cause a significant change in your system, so it is a bug. Or you are modifying the code using a clip-like manner, which has changed the opportunity of your program code changed. Because you join new features in the way you use clip, you have to change it, you have to modify it, but because the complexity of the system makes you unable to take care of it, you don't know what places need. modify. So when you change, you want you to modify the place, so that you don't cause a bug. Since users always have some new ideas to cause changes in the system, your program should be easy to modify, this is why it takes to reorganize.

Tip: When you need to join a new feature, it is difficult for this program code to make you to modify it to join the new feature, you need to reform this program first to make it easy to add new features, then To join the new features.

The first step of reorganization, please make sure you have a series of test protection. Otherwise don't be easily reorganized. Because you don't test, you don't know if you have changed the original behavior.

TIP: Please confirm that you have a complete test before reorganizing. And this test must be automated automatically.

The primary goal of the reorganization is to decompose excessive program blocks (such as large methods) into small blocks, because the relatively small block program is easier to manage, easy to operate or move. At the same time, the reforming step is not too big, and each time only makes a change in a small step, then performs testing to confirm that your change is destroyed. TIP: Reform is to change the program with minimal steps, because if you make any mistakes, you can easily find a bug.

Good programming code should easily communicate its intent, and the variable name is a key to clean program code, don't be afraid to change the name of the matter to make it more clearly express. The communication between the program code is very important, and the most important task of reorganization is to improve the communication of the program. The communication between the program code is not only to let others know the program you have written, and it is also what is your understanding of the program code.

TIP: The people who are stupid can write a program code that makes the computer can understand, the program code written by a good programming is allowed to understand.

The result of the reorganization can be better distribution of responsibility, while the process code is easier to maintain. Such a program code is considerably different from the programmatic program code. The programmatic way is that we are often used, but as long as you often reform, you will gradually use the objective orientation of the object and will not go back to the procedural code code. When you start to reform, you have to master the important rhythm: test, small changes, test, small changes, test, small changes.

------------------------------------------ from: "Areca_chen.tw "

The definition of reforming is defined in terms of noun: refactoring changes in the internal structure of the software to make the software easier to understand and reduce the cost of maintenance, not to change the external behavior. Definition of verbs: Refactor applies a series of reorganization recombinant software structures, without changing its external behavior. Regene is not just a cleaning code cleaner, and its further meaning is to provide a technique to clean up code in a more efficient and controlled manner. Because you will know which reorganization should be used and how to use this reform to avoid causing bugs and test it at any time. The primary goal of reorganization is to make the process easier to understand and maintain. (Another relative method is to adjust the speed of execution. The other characteristic of the reforming is not to change the external behavior of the software. There is another consideration when the software is developed, called two caps. A hat is reorganizing, and the other hat is increasing new features. You should not wear two hats at the same time. That is, do not add a new function after reforming, do not reorganize when new features. These two work don't do it at the same time. Because new features means changing the external behavior of the software, while the reformation is premised on do not change the external behavior. Therefore, if you do the two work at the same time, it is easy to make you mix and create an unexpected bug. When you develop a software; you will join your new feature, pick you up your program, so you can make your follow-up work more easily, so that you can do it. So your development is frequently switched between the two hat, and the time spent each time is about 10 minutes.

------------------------------------------ from: "Areca_chen.tw date: WED APR 24, 2002 11:02 Amsubject: Refactoring Notes -3-2

Why do you need to reorganize? Reforming Improduction Software Design: In the software development process, the programming designer tends to modify the code. The reason for modification may be because short-term purposes or because there is no complete understanding of the original design, therefore causes the program code to lose structure, and therefore not easily understand its structure via the reading code. The case where the program is lost structure has accumulated effect. The more lack of structural program, the more difficult to maintain, and the more difficult to maintain it, the more it is no structure. The code of poor design often contains many duplicate program, which do the same thing in different places. Therefore, the elimination of repeated program is the most important thing to improve design. This provides simpleness for future maintenance work. Reducing these repeated program codes do not have the speed of execution, as these executions still exist. The big program is more difficult to maintain the work, because the same code code scattered four-way designer can not be fully capable. This is a good design guarantee by eliminating the repeated program code to ensure that anything mentioned by the program code is only one time and the only one. Reforming makes the software easy to understand: The program code is mainly written to the computer, but don't forget that when someone is going to maintain these programs, these programs are still going to see. Therefore, when the program designer is only considering the program code, it is only necessary to perform it and ignore these programs in the future. Reform can improve the readability of the program. [Question: What kind of program code is readable? ] And often need to take care of the maintenance code is the programming designer for writing these programs. The programming designer can't remember all the programs he wrote, so when he maintained, you need to check the program. So all things are to be placed in the program code. [Question: What is written? 】 You can learn from the unfamilia program code from the reorganization, from the reforming of your brain, then change the code to respond to the results you know. Finally, you will then test the results of your understanding and change to see if it is still possible. After reorganizing, you can see the details you can't see before. Reforming helps you in worms: Understand the code also helps you prevent bugs. Perhaps some people can view a lot of pricard code and find a bug, but most of the people have no way. Reforming can reduce the chance of bugs to reduce the chance of the bugs and the clay code structure. So you don't have to be a great programming designer, as long as you have a good habit, you can be a competent programming designer, and the reforming is a good habit you need. Reforming can make the speed of speeding your program are an important factor in development speed. There is no good design, you can still be very fast, but how long does it take for a long time will gradually decrease. Because you spend more time to defrust instead, not add new features. You have changed any changes to the completed programming allow you to take a lot of time to understand the system and find repetitive programs. In order to join the new feature forced you to patch vulnerabilities in the old can be found. Good design is also an important factor in the speed of maintenance code. Reform can avoid the design of the system or even improve the design, so you can improve the speed of development. ------------------------------------------ from: "Areca_chen.tw " date: fri Apr 26, 2002 10:00 Amsubject: Refactoring Notes -3-3

When is it necessary to reform? How long does it take to reform when you arrange progress? In fact, the reorganization should not pre-leave the time, and the reorganization should be ready at any time. You don't have to decide when you need to reorganize when you need to make another thing. The three-stage rules Don Roberts put forward the so-called three-stage rules: you just do it when you do one thing. When you do a similar thing for the second time you will hesitate, but you still do repetition. When you do something similar to the third time, you reorganize. Tip: Talk three times, you will be reorganized. When you add a function, you have to reform when you add a function, you have to know the program you have to modify so you must reform first. These programming codes may be you or others, when you want to know more about these programs, you consider whether you reorganize to make the scheduled code more obvious. If you can reorganize. Another situation is that when the original design is not so easy to make you add new features. You don't have to worry about the previous deviation, you just reorganize to meet the needs of new features. This is not to provide easy access to new features and this is also a faster and gentle way. When you need to be in a worm, you have to reorganize the same for inquiry you want more to understand the code, and you can also provide help. When you know that there is a bug in the program, the representative code is not clear enough, so the reorganization can also help you find a bug. When you review (REVIEW) program code, you have to renegate some organization implementation code review, but the results are not very good. The program code review can help the knowledge of knowledge, let more people understand more concepts of large systems. And the most important thing is that the program code must be clean [Question: What is a clean program? ]. The program code written by myself is very clear, but others can don't necessarily, this is very common. The program review also provides an opportunity to make your own opinions. Reform can help you review the program code of others. When you have an idea that some places can be more simple, you can do it on the spot. When you do reforming, you will know more about the program code, and the reorganization you do is also useful. You don't have to imagine how you should do it, you can see what you think now. At the same time, I can know more about it. The understanding of this level is not reached. Renewal and help the program code review to achieve specific results. Not just concept, the specific implementation can be achieved on the spot. You can accumulate your knowledge from your behalf. The program review requires a group to complete, preferably by an examiner plus the original programming designer. From the direction of the review personnel, everyone will determine how to make simple reforms and then do it. The large design review (Design Review is easier to get many views in large teams. The display program is not the best way. Use the UML map and the entire plot of the CRC card. Therefore, the design review adopts team approach, and the program code reviews adopts individual reviewers. Double-fixing design in XP will perform the work of the review to the limit. All developments are completed in a step machine. In fact, this is a persistent program review, of course, the reforming is continuously carried out throughout the process. ------------------------------------------ from: "Areca_chen.tw date: fri Apr 26, 2002 2:55 PMSUBJECT: Refactoring Notes -3-4

Why is it useful to reorganize - thekent beck has two values, one is today it can do for you, the other is tomorrow (future) it can do for you. When we write a program, we only consider today's value. And when we are in worms or add new features, we are upgraded today's ability to make it more valuable. You must understand that the system is just a part of the story. If you can do this today's things, if you do the way to make tomorrow's work can't be done tomorrow, then you will lose. Please pay special attention to it; do you know what you should do today, but for you will not be confirmed tomorrow. There is any possibility tomorrow. Since the future changes are very difficult, there is no benefit to the project, so master the current needs, and will be solved when the future may be left. Reform is this means of solving problems. When you find that yesterday's decision is in today, you can change this decision, then you face the problem of today's question. Similarly, when you find that today's decision is improper, you can also change today's decisions. What is the reason for how to handle the code: • The program code is difficult to reader is difficult to maintain. The program code has a repetitive logic is difficult to maintain. The program code requires additional behavior, and these additional behaviors need you change the running code that is difficult to maintain. The complicated conditional logic in the program code is difficult to maintain. So we have to make program code easy to read. Every logic exists only one place and is the only place, which does not allow any changes to existing behavior, and make the conditional logic expressions as simple as possible. Regeneration is a program that handles running code and increasing its value, does not change its behavior and enhances its quality and let us quickly continue to develop. ------------------------------------------ from: "Areca_chen.tw " date: Tue Apr 30, 2002 10:56 Amsubject: Refactoring Notes -3-5

What do you should tell your manager? If your manager is a technical background, it should be very simple. If your manager is quality orientation, you can cut from the angle of quality. The use of reorganization in the program code is the best way. Because the most important task of technical review is to reduce bugs and improve development speeds. If some administrators claim that they are quality oriented but pay more attention, you'd better "don't say"! It's best to do it directly at this time, let the facts prove everything.

------------------------------------------ from: "Areca_chen.tw date: Tue Apr 30, 2002 10:57 Amsubject: Refactoring Notes -3-6

Roundabout and Reforming - Kent Beck Computer Science This discipline believes that all issues can be resolved through some degree indirect. - Dennis Debruler reorganizes to break up large objects into many smaller objects, and break up large methods into many smaller methods. Indirect is a two-sided blade, you break one of things into two means you have more things to manage, and when an object entrusted another article will make program designers more difficult to read the code code. It is therefore desirable to reduce indirectness. Don't conclusions so soon, the indirectability will compensate, the following is a few ways: logical sharing makes it possible:, for example, a subMethod can be called in different places, or the method in the parent category can be Shared in all subcategories. Expression of the interlaced intent and the expression of the actuality: Choose meaningful names for each category and method to express your intentions. The category and method contains understanding of your intention. If your containment is a smaller fragment, you can write most of its own information about its own structure. [Note: It is not the direct actual process code to return your intent, but first express your intention to make your intentions in indirect. ] Isolated Change: I use the same object in two different places, and I want to change their behavior in one of these two conditions. If I change the object, I rash at the same time. So I will make these two items to change the behavior of one of them. Conditional logic encoding: Apply multiple mechanisms elasticity and clear expressive logic, change the conditional change to a message (Messages) can reduce repetition code, increase clarity and elasticity. This is the so-called reforming skill (GAME): Maintaining the current behavior of the system, how do you make your system more valuable, including enhance quality or reduce costs? Through this skill, the most common change is to review your program. Find one or more places that generate "indirect interests" and then put indirect features and do not change the existing behavior. At this point your program has the value of future accessible use because it has better quality. Second, in the reforming skills, it is not often the indirect part without value and will be taken out. Generally, this is in the form of an intermediate method. This method is just used for some intent, but this intent is not long. exist. Or maybe it is a component, this component is your expectation of sharing or multiple but final proves only in one place. When you find something like this parasitic in indirectity, remove it. The same thing you will get a more valuable program, not because it is only one or more of the four quality, but because of the use of fewer indirectity, the same value is obtained from quality. ------------------------------------------ from: "Areca_chen.tw "

Reforming issues When you learn a new technology, this technology may greatly improve your ability. But it is often ignored the crisis of this technology hidden crisis. Any technique has its limit. There is a problem with the program of the database using the database. Since the program of the database is closely bonded to the data structure (SCHEMA). Another reason is data migration. There is a small relationship between your system's data structure and object mode, change the data structure [Note: Refectation Data structure] or forced you to migrate information, this is a big project. The use of non-objective databases to deal with this problem is that there is both of your object module and the database module, which can help you disaggregate the individual changes. affect. When you update the other side, you don't have to update the other side, you just update the intermediate layer at the same time. The intermediate layer provides elastic but also increases complexity. There is no need to reforiently consolidate, maintaining an intermediate layer in many cases, if the intermediate layer is still needed when multiple databases or complex database modules. At the beginning, you don't have to build an intermediate layer, as long as you find that your object module is volatile, the intermediate layer is added. The materialized database is favorable. Some object-oriented databases provide automation based on object migration. This provides effort but time consuming work. If the information migration does not know automation, you must manually migrate the data more time consuming, and must simultaneously distinguish between the data structure and the category structure and the field. Changing the interface object has an important feature that allows you to change the actual, do not change its interface. Because both the internal work is not affected by the client that uses this object. However, there may be more problems that can cause the interface of the object. When the renestability is used to use the rename (rename), the topic of the change interface is involved. When the name of the change method, if you can contact the program code of all calling this method, you can change the program code of the call to this method. The problem that the problem in calling this method is that you can't find or change. At this time, the interface of this method is called "Publish Interface" (a Public "interface. At this time, you must make more complicated. The way to deal with the original interface and not just rename, unless you have changed this unless you have used it. But it is not too difficult. As long as the original interface (the method of reserving the name) is called the new interface. This allows two interfaces to coexist. Never copy the old interface to modify the new interface, this has a repeated program code. In Java, you can also use its "Deprecation facility" to indicate this old method is not recommended to let your user know this method will no longer apply. The retention interface is generally possible, but some pain. You must maintain an additional method for a while, it will complicate the interface. Another way is to issue your interface. This doesn't mean that you can't do this, especially if you develop, is for external use. It is emphasized here that all developers in the development team have issued the interfacia to others. Especially in tissues, these programs are individual management. Of course, you can also avoid this problem like all the programs like XP, you can avoid this problem. TIP: Don't conduct your interface. Modify your program code has rules to make the reforming and easy. Changing the interface in Java has a special problem: an exception is added to the exceptional throwing sentence. This has not changed the identification, so you cannot use the delegation to process because you cannot compile. You can choose a new name for a new method to call the new method to call the new method, and will convert the exception to the unchackd. You can also throw out a capture exception, but you also lose the ability to check the check. When you do this, you can inform you that this exception becomes an exception to pass in the future, and they can sometimes put the handler (Handlers) into their code. So a better way is to define a parent category in the package to ensure that this exception is announced in their throwing words. This way you can define the exceptions you want. However, this approach is invalid for only the caller who knows the general exception.

[Question: Where is the problem? ] Design change is not easy to reform (Design Changes That Are Difficult To Refactor) You reorganize it from any design error (Can you refactor your way out of any design miss, or some design decisions are extremely The core is caused by you can't rely on the reforming of you. There are no many information on this section to be evidence. Sometimes it is sometimes easier in practice, there is a variety of situations. At this point you can use the imagination. When you consider the design of various alternatives, you can consider the difficulties of reforming from a design solution to another. If it is not very difficult, don't worry about how to choose, as long as you choose a relatively simple design, it does not cover all of the potential needs. But if you can't find a simple reorganization, you need to be more designed to design. However, this situation doesn't seem to be much. When isn't you reorganizing? When you feel that you should rewrite from your head. When you think that rewriting is easier. This decision is sometimes not easy, but there is no good guidance to tell you. There is a more obvious sign that it is no way to run when the current program code is. At this point, there is no matter how you try to test or have a lot of bugs. Of course, the reorganization is only useful after your program code can be performed correctly. It is meaningless to run the program. Another path is to encapsulate a large piece of program into components, at which point you can use the refactor-versus-rebuild to process a component at a time. This is a feasible way, but there is no detailed rule to follow. But for a legacy system, this may be a direction. Another situation is that when you are facing the handling deadline. At this time, the reformed productive forces is not as good as it is handed. In addition to facing the deadline, you should not resolve. The evidence shows that the reforming can increase productivity, and there is no time to represent you need to reform. ------------------------------------------ from: "Areca_chen.tw "

The results of reforming and execution speed reforming may result in reduced execution speed, but also inspiring adjustment execution speed. So the best way is to first write easy-to-advice and adjust the speed of implementation. There are three ways to write speeds:

The most rigorous way is to use the "Time Budgeting", which is often used in a harsh timely system. This approach is to cut the design into one component, each element gives a certain resource budget-time and space. These components must not exceed a given budget, but the mutual exchange time budget is allowed. This method is strictly controlled for execution time.

The second way is a way to continue monitoring. This approach is to maintain its high execution speed wheels at any time. This is a general manner and is intuitive. But the effect of implementation is not very good. Because changes to the execution speed tend to reduce the speed of the development. Those programs that improve the execution speed are scattered in the system, and each of the programs that improve the execution speed is just a narrow intention of the behavior of the program. In fact, it is only very small part of the program code related to execution speed. If you improve all the program code, it is wasted, because most of your improvement is not too frequent. The more it takes time to improve, and more waste time is due to lack of clarity.

The third way is to improve those programming codes that can receive a speed of 90%. This approach is to construct your program in a good decomposition method instead of performing speed until the execution speed phase is adjusted, it is generally developed. In executing speed optimization phase, you can adjust the execution speed of the program in a specific step. Attack in a background (PROFILER), this background monitoring program and tells you the time and space used. In this way you can find a small number of slowers. This is another improvement in the way you have improved your performance. Because this way is only for small parts to improve you can save a lot of time. When you complete and compile, test and perform the result of performing a speed improvement in the same background, if you reply change the result, re-try other ways until the result is you satisfied. A good decomposition program has two helpful benefits: 1. Let you have time to adjust the execution speed, because you have a good decomposition code, you can quickly increase your function, let you have more time to focus on Perform speed. (Use background to let you put the time in the right place) 2. Let you have more detailed blocks as an analysis of the speed. Your background guides you to a small part of your problem, and make it easy to adjust. Clear programming, you can easily understand where your program code may improve and which type of adjustment is more feasible. Reability is really possible to reduce the execution speed of the program, but if you still continue to reform, you can finalize you adjust the speed of the execution.

------------------------------------------ from: "Areca_chen.tw date: Thu May 9, 2002 8:13 Amsubject: Refactoring Reading Note 4-1

Smell in the program code

-------------------------------------------------- ------------------------------

This chapter tells us how to write a good object guide.

In addition to knowing the use of reforming and how to reorganize, the most important thing is that you have to know when to be reorganized and when the reform is completed. Martin and Kent believe that the program code needs to be reorganized to determine according to the so-called "taste of the code". It is called "taste" because it is difficult to specify, and there are many blurred spaces that can be specified. So many of these specifications are relying on people's intuition. The problem of reforming and the problem to be solved is often indirect. So learning the reorganization requires you to cultivate your feelings. If you have too much solid variable, how much travel code is too much. Then use the items of the items listed in the book in the book, you will have the "odor" of your program code.

-------------------------------------------------- ------------------------------

Duplicated Code Repeated code is the first need to reform in the smell of the program. As long as you find the same program structure in more than two places, you need to be reorganized. The most simple in which two methods in a category have the same representation. You can use the "Shuang Method" to make two places call the same program code. Another common situation is that there is the same representation in two brothers, you can reduce the repeated program code using the "Shuang method" or "field shift". If these pricings are just similar to not exactly, you can use the "quenching method" to distinguish the same part and different parts. At this point you find that you can use the "formation method". If these methods do the same job, they have different algorithms that you can choose one of the relatively clear algorithms and use the "alternative algorithm".

If there is a repetitive program code in two unrelated categories, consider using the "Quenching Category" in one of the categories, and use this category as a component in another category. Another possibility is that one of these categories is only one of these categories, or the method belongs to the third category, which is the original two categories, you need to decide where this method is more meaningful and ensures only There appeared there.

[Reflections: Repeated program code has considerable obstacles for the maintenance of the system. When you need new features or insect insects, once you involve these programs, you must find all the same partial changes in the program, once there are some Did not find a bug. At the same time, the repeated program code is conducive to the slimming of the program, and because of the clearness of the functional responsibility, it is conducive to the reading of the program. ] ---------------------------------------- ". TW " date: fri may 10, 2002 1:28 PMSUBject: Refactoring Reading Notes 4-2

Long Method [Reflections: Long Method Means the responsibility of this method is too large, there are too many operations. Therefore, the long way is not easy to read, don't say it. At the same time, many operations are gathered in one way these operations cannot be shared to use indirectly caused the repetition code to use indirectly. Therefore, long methods need to divide them individually operators to become individual methods to share, because it is easy to easily maintain. ]

The most important feature of the object guide design is "short method". People who have expired OO often feel that the program seems to be everything is doing, and it is a series of endless delegates. This is the foregoing indirect interests "- Expranation, Sharing and Choosing - this is supported by a small method. Because long methods are not easy to understand, the old programming language uses "Subroutine" or function, but it is still not easy to form a small method. OO can reduce this programmatic call. But for the readers of the program code, it is still very troublesome, because he needs to know what this subprogram is doing with the "Subprocdure" transform background (the content). The current development environment allows you to view two methods simultaneously, help to read, but the most important key is that these small methods have a good naming rule. If you are named, you don't need to look at the entity (that is The actual program code).

A small method has a net effect is that you have to actively decompose (Decomposing) methods. The way we tried is that when we need to annotate certain matters, we write a method to replace. The program included in this method is annotated, but the method is to name the program code instead of how it is named. The method of this method can be a group of programs or even a line code, and even the call (method name) of this method is longer than the program code it replaces. This approach allows the method name to express the program code. The key here is not the length of the method but what is the fundamental difference between the method and how to do.

99% of the method should be shortened using the "Queening Method". It seems a new method in finding a better part. If you have a method, there are many parameters and temporary variables, you need to "quenching methods" make this method easier to read. You can also use "Use query replacement temporary variables" to reduce the use of temporary variables. A long string of parameters can lose weight through "Parameter Items" and "Save Complete Items". If you have tried there still no way to reduce the number of parameters and temporary variables, you can use the last killing trick "to replace the method of method".

How do you decide that the program code needs to be quenched, there is a technology to find the information, this is a certain type of important language signal. The marking code indicated an annotation tells you that it can replace it with a method and the name of this method is based on this annotation. It is also worthy of quenching only one line code, because the representative needs to express some intentions. [Note: This means that the program code does not require an annotation or explanation file]. Conditional representations and round circles are also important signals that require quenching. Use the "Decomposition Condition" processing condition representation. The way the treated loop is to quench the roll-back circles and the procurement code in the back ring into its own method.

------------------------------------------ from: "Areca_chen.tw date: Mon May 13, 2002 2:30 pmsubject: refactoring reading note 4-3 Category (Large Class) [Thinking: Big category indicates that there are too many methods or instances Variables are prone to repeated program. Therefore, you need to divide a large category into a small category. ]

If a category does too much, it is displayed too many instance variables (instance variables). If a category has too many instance variables, it is a repeated program code. [Question: Why is there too many instance variables that cause duplicate program? How big is the category of which elements that contain which elements. ]

You can use the "Quenching Category" package several variables. Pick a variable that is meaningful to each other into one component. Second, a common fixed device for certain variables in a category [Note: variables or environmental status of each category must be used. ] Or suffixes [Note: Processing after the fixed device is used. An element can be considered in consideration of a component. If this component can be used as a secondary, you can use the "Qualification Category" to process. Sometimes a category is not always using all its instance variables, you can use "Sold Category" and "Quench Category" multiple times.

The same category with too many programs is also the fierce of the repeated program code. Therefore, a large method is reorganized into several small methods is a way to solve it. Another trick is based on how to use this category and use the "Queening Interface" for each usage, which can provide you decompose this category.

If your big category is the user interface (GUI), you can move data and behavior to the domain object. This approach may maintain some repetitive information in two places and maintain its synchronization. "Repeat Observation Information" can handle this situation. At this point, especially if you use the Abstract Windows Toolkit AWT component, you can remove the GUI category according to this method and replaced with SWING components.

------------------------------------------ from: "Areca_chen.tw "

Long Parameter List [Thinking: There must be the meaning representative of each parameter when using the method of long parameter column, so it is not easy to understand and read. Although the use of a wide range of variables can be improved, it is easy to cause variables that are changed by other objects without knowing their risks. Because the objects can carry multiple data, it can simplify the parameter column using the object delivery information. At the same time, the method can obtain information required from the information of the material that needs to be supplied, which can be protected by the information object. ]

Traditional program often utilizes the information required for the way the parameters is provided. This includes using a wide range of variables and a wide range of risks in use. The object-oriented program uses another mechanism when you need some information, you can ask other items to be provided. Therefore, you are not the required parameters according to the needs of the method, but to pass enough objects to get the required information. And a method needs to be provided in the Host Class). Therefore, the OO program is far less than the traditional program. Too many parameters is that it is difficult to understand, it is difficult to use, because when you need more information, you often need to change. These changes can be lowered through the object.

When you can get the information of a known item to get the parameters, you can use the "method to replace parameters". This object may be a field or another parameter. Use the "Save Complete Items" to get a batch of information from one item and replace these parameters in the object itself. If the information you need is not an object to be available, use "Bring Parameters".

Here is an exception that when you are clearly unwilling to generate a dependence between the object being called with a larger object. It is reasonable to unwield data and separately in parameters, but you need to be particularly careful. If the parameter column is too long and too frequent changes, you have to think about your dependence structure. [Thinking: The relationship between objects is also a commission relationship, which is too complicated to cause which consequences. That is to say, it is too close to make the elasticity of the program. When you want to change an object, it is difficult for dependence. However, the principal relationship is the foundation of the object cooperation in OO, which has too many examples in the design style (Design Patterns). ] ---------------------------------------- ". TW "

Differences (DIVERGENT CHANGE) [Reflect] Differences Changes are elasticity that must be provided in response to different external demand programs. If the output may have a variety of different formats (such as pure text files, HTML files, etc.), and Only one of the designs is designed, but it is expected that there may be other possibilities, so the procurement must reserve the possibility, or use the reform when adding new functions to have this elasticity.]

We make our program structure for change. When we change the program, we hope that only a certain point in the program is changed without affecting other parts. When your category changes are due to different reasons; such as: Whenever the database changes you need to change some three methods or changes to a few ways due to new financial needs. Therefore, changes in each demand will cause certain categories to follow changes, and newly added categories should express these changes. To clarify this way you have to define all possible changes and use the "Quenching Category" collection. [Note: Create some "interface" to replace the corresponding item according to the change. ]

------------------------------------------ from: "Areca_chen.tw "

Shotgun Surgery [Thinking: When you do a change in the program, it is found that it is necessary to change to many places in the program, indicating that these needs have changed, so they have relevant places The collection of reforming will be convenient in one place, while providing a better structure. ]

The change in disagreement is similar but relative. When you do some changes, you need to make small changes in many different categories. When the change is spreading around you, you are not easy to find a place where you want to change and ignore an important place.

At this point you can use the "Mobile Method" and "Mobile Boot" to put all changes in a single category. If there is currently no category suitable, set it. Generally you can use the "Row Category" to put a whole pile of behavior.

Differential changes are many different changes in a category, while the bomb surgery is a change that changes will move to many categories. In both ways, you want to make changes to the category of one-on-one relationship.

------------------------------------------ from: "Areca_chen.tw date: fri may 17, 2002 9:06 Amsubject: Refactoring Reading Note 4-7

Feature Envy [Reflections: When you design a method, this method requires other items to provide most of the information, at which time this method can be considering the information of this method directly to the material. . The advantage of this is to reduce the complexity of the program code. It is also relatively compliant with the principle of OO: the data and processes of the data are wrapped in one item. ] The focus of OO technology is the technique of wraping data and processing data. There is a typical taste: a method seems to be more interested in other categories rather than this method of host category. It is most common to focus on information. Most of the time a method is to start the GET method for other objects to obtain some values ​​to calculate the result value. The solution is obvious, this method obviously should be in that place, you can use the "Mobile Method" to move it to it should exist. [Note: This method should be moved to its most frequently calling the objects of the information. ] Sometimes only partial methods have this characteristic, you can use the "Sold Method" in these methods first, then place it to the place where it should exist in "Mobile Method".

Of course not all methods are true. Often a way to use many other categories of features, what should I exist? Generally see which category of information is the host of this method. Or use the "Sold Method" to put the method to separately put the method to individual appropriate categories.

Some styles will break this rule. The Strategy Style and Visitor (Vistor) style is in the Book of GOF "Design Style". The self delegation of Kent Beck is also. But the most important thing is to put together the part of the change. The behavior of information and reference to these materials is usually placed together, but there is exception. When an exception occurs, we put together the behavior that will change together. Strategy style and visitor styles make your convenient change behavior, because they will be rewritten, indirectly reduces the cost of future changes.

------------------------------------------ from: "Areca_chen.tw "

Data CLUMPS [Reflections: Package of objects, so its package should be relevant (relevance to handle data), so the relevant data cluster is advantageous in one item in a substitute, clearly express its meaning . ]

Data projects are often easy to cluster together. You will often find three or four data clusters in many places, such as: information in some categories and parameters in many ways. A string of information is actually a group of their own objects, so let's find how to find these data fields, use the "Quenching Category" to store them in one item. Then pay attention to the declaration of the method, use "Parameter Items" or "Save Full Items" to help lose weight to reduce parameter columns and simplify calls. Don't worry that only part of the new item is used, you will earn as long as you replace these fields with new items. [Thinking: When all people who access these materials are used in this object, their changes in the information will react in other people's materials. This should be a major interest in replacing the information field in the object. ]

------------------------------------------ from: "Areca_chen.tw "

Primitive Obsession [Thinking: The original type of information provided using the language is a traditional programming language. However, the object-oriented items include the procedures for processing, so we should use OO to wrap the original data to be wrapped in objects in the object, and any way to operate is performed through the object. ] There are two types of information in most languages: record (RECORD) type and the original type of statement that constitutes a record. Using objects can bvreate these languages ​​of these languages, the original type of original type and large categories of bounded lines [Note: The record itself is this purpose, but it is better to use the object. However, the general item novice is not good to use this advantage. ]. [Reflections: Original data does not operate the ability to replace the material processing ability. At the same time, the object can represent "objects" in the actual world. ] If the Money category can contain quantities and amounts. You can use "replace data values" in the item value in individual data values. If these data values ​​are the type code and its value does not affect behavior, "Sub-Sign Codes" is used in the category code, if you have conditional, use the "subcatenal replacement marker code" or "status / Strategy style replacement marker code. " If you have a group of columns to use "quenching category" together. If you find that the parameter column is originally used to use "Bring Parameters". If you

Areca chen

Www.dotspace.idv.tw

Areca_chen.tw@yahoo.com.tw

Arecagiga@giga.net.tw

------------------------------------------ from: "Areca_chen.tw date: Wed May 22, 2002 10:09 Amsubject: Refactoring Reading Note 4-10

Switch Statement [Reflections: Disadvantages with Switching Standards Because each Case's option is often similar, only a small number of differences, this is the repeated program. It is easy to replace the switching as long as the multi-type mechanism is used. ]

The most obvious feature of OO is relatively small to switch statements (such as CASE clauses), because the switching statement is the root of the repetition code. You will find the same switching statement spread different from the program. When you join a clause in a switching statement, you must update all the switching statements. The OO multi-type concept provides exquisite way to handle this problem.

Whenever you want to use to switch, you have to consider a multi-type. General Switching statements are switched between signs, use methods, or category handling flags, first use "quenching method" quenching and switching, then use mobile methods ", then put it in multiple categories, then you must decide Used for subcategory replacement marker code "or in status / policy style replacement mark code."

If you just use a small part to use the switching statement, use multiple times too much trouble without want to change, using the "Subject to the parameters in a clear method" is a good choice. If you have an empty (null) in your CASE condition, "bring an empty object."

------------------------------------------ from: "Areca_chen.tw "

Parallel Inheritance Hieranchies [Thinking: When two categories hierarchical architectures are dependent, whenever one of them increases the subcategories, it must be added to another category corresponding to another category. This class-level architecture is likely to cause coupling adverse maintenance. ]

Parallel inheritance hierarchical architecture is a special case of bomb surgery. When you inherit a subcategory from a category, you must also inherit a base in another category. You can remove this situation using the "Mobile Method" and "Mobile Boot". [Question: What is the situation will cause two categories of inheritance level architecture? Is it a case in which it is a case? ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ---- From: "Areca_chen.tw"

Lazy Class [Reflection: How is the category of no value? ]

There is too little thing for a category (or whether pay for itself) should be removed. If this category is a subcategory, you can use the "Wattrace level architecture" to remove him. Recently useful components should be handled out using the "Inpass Category".

------------------------------------------ from: "Areca_chen.tw date: Mon May 27, 2002 10:44 Amsubject: Refactoring Reading Note 4-13

Speculative Generality [Thinking: XP emphasizes not to prepare tomorrow. So don't consider the parent category when you design a category architecture. The design of the commission is not too early, and it will be done. ]

When someone wants to prepare for some of the features that may be needed in the future, you can smell this taste. This situation is often difficult to understand and maintain. If you have an abstract category, there is not much to use "Wattrace Level Architecture". Unnecessary commission can use the "embedded category" processing. Unnecessary parameters in the method can be removed using "Removing Parameters". The method name contains the old abstract name to use the "Method Removement" processing.

Pure theoretical universality can be excavated through the method of the use of the method or the test case. If you find this, remove him and use test inspection. If there is a method or class that is used to assist the test case to provide the legitimacy of the legitimacy, you still have to retain this method or category.

------------------------------------------ from: "Areca_chen.tw "

Temporary Field [Reflections: Traditional procedures in order to handle data, there will be many temporary variables, these variables are very difficult to understand the maintenance personnel (whether it is original writer), which includes variables. The stored materials represent what and which arithmeters will pass through this variable, and even some people repeat this variable in the program code to store different information. The processing method first reduces the use of these entity variables as much as possible, followed by centralized these variables and processed program code. ]

Some specific applications in the object are only used in specific cases. At this point, this program code is difficult to understand. It is difficult to understand what these variables represent me.

Use the "Sold Category" to establish a space to store these variables and put the relevant program code in this component. Use the "Band Empty Object" to reduce the use of conditions to reduce the use of variables.

The general usage of the temporary field is that when your ranking algorithm is complicated, there will be some storage middle temporary information, and generally do not want to use long parameter columns to transfer data to the variables. And these temporary variables are useful in this algorithm, and it is meaningless to leave the calculation algorithm. You can use the "Queense Category" to focus the relevant variables and methods, this new object is called "Method Object" [BECK].

------------------------------------------ from: "Areca_chen.tw date: Tue May 28, 2002 8:38 Amsubject: Refactoring Reading Note 4-15 Message Chains [Reflection] This is due to object-oriented characteristics (indirect or commission) The abuse, the situation of the message chain is quite resistance to the reader code. When the intermediate object does not do any processing, it is only called another object to handle it, we must think about whether the call to handle this message can be considered. The message chain specifically points out that a separate chain is not a specific inheritance structure. (We can imagine an exception to make a message chain when an exception is handled, there is no way to handle it until there is an exception hand to handle this exception. In fact, every exception processing machine is still needed to determine whether it is handled.) ]

The message chain is when a client requires a service to an object, and this object must also request a service to another, or even the second object must also serve the third object, so that I have been going. You can see a long stringing GET method. This situation allows the client to be closely combined with such cruise structures. To change this indirect relationship, you need to change the client.

There are many ways to use "hidden commission". In theory you can move each item on the chain, but this may make each intermediary object becomes a Middleman. It is preferred to see which one of the finally used is, and then try to use the "Shuang Method" to remove the program segment to form a method, then use the "Mobile Method" to put this method to the bottom of the chain ( Note: Original caller). However, if many of this chain, many of the uses of objects need to continue to cruise the rest of the remaining chains, add a method to execute.

------------------------------------------ from: "Areca_chen.tw ""

Middle Man (Middle Man) [Reflections: The principal's aimed is to be responsible for objects; concentrating the related or similar responsibilities in one object. Other objects require these functions to perform it. Each method in any object should have its own responsibilities. Through the entrustment, it should be just a way to help other objects when they perform their duties, rather than directly entrusting the entire responsibilities directly to other objects, otherwise this method is basically meaningless. You only need to call this item with appropriate responsibilities directly. ]

The package accompanying this object is to be commissioned. The middleman is the entruster. If you find that a category finds it is to entrust other categories, you can use "Remove Intermediates" and communicate directly with those who know how to perform jobs. If there is only a few ways, use the "Inline" call object. If there is an extra behavior, you can use the "Hierarchical Architecture Replacement" to convert the middleman into a subclass of the actual object, which allows you to expand the behavior without chasing all delegates.

------------------------------------------ from: "Areca_chen.tw date: Wed May 29, 2002 8:47 Amsubject: Refactoring Reading Note 4-17

Inappropriate Intimacy [Reflections: The object access to the internal private parts of the other objects are encapsulated. These two objects directly inherit a parent class. Alternatively, a common part is an object is also a way of processing. ] When category excessively exploring the private parts of other categories, representative of this object is not properly related. Use the "Mobile Method" and "Mobile Boot" to reduce intimate relationships. See if you can use "Change Bidirectional Binding to One-way" to modify the configuration. If these categories have the same interest, use the "Sold Category" to put the common part in a safe place to make it the honest (honest). Or use the "hidden commission" to make other objects as the medium (Go-Between).

------------------------------------------ from: "Areca_chen.tw date: thu May 30, 2002 8:25 Amsubject: Refactoring Reading Note 4-18

There are different interfaces, alternative classes with different interface [Thinking: The method of the same responsibility is concentrated in the principle of the object "is not only the object of the object, while facilitating maintenance. ]

Some methods do the same job is only different, and "Method Renname" is used to change its name. But this is generally insufficient, and it is not enough to indicate these categories. Continue to use the "Mobile Method" behavior to the category until the protocols (protocols). If you think that "mobile method" is too lengthy, you can use "Queen Parent Category" to assist.

------------------------------------------ from: "Areca_chen.tw "

Incomplete library class (INCOMPLETE LIBRARY CLASS) [Thinking: How do you expand your program class category when your functionality is not satisfied? Here is two ways. ]

Reuse is the goal of OO. The re-use skill is generally the application library category. But it is often not very convulsions that establish program library categories. When we really construct it, we need to know what we need. So the establishment of a program library category is not a very easy thing. The format of the general class library category is not very good. Sometimes it is difficult to modify it to do it. At this time, the "mobile method" of tryied-and-true cannot be improved.

There are several specific tools for this odor: If you just provide some methods you want in the program library category, use "Bring External Method". If you are a complete extra behavior, you need to "brought into area inheritance".

------------------------------------------ from: "Areca_chen.tw "

Data Class [Reflections: The information category is not a smell, its odor is from improper designs such as information hidden or information protection. The information category seems to have no special effects, but in the process of growth of objects, it is also responsible for the management of information. ]

In addition to the data fields and the SET and GET methods of these materials, there is no other thing. This kind of category is generally more for other objects. (DETEL) Early these categories have some open fields, and use the "packaged field" before doing any other action. If you have a collection field (Collection Fields) Check if the appropriate package is used, if you use the "Package Collection". Use "Removing Settings Method" for the column that must not be changed. Looking for a SET and GET method in other categories, trying to move these behaviors to the data category with "Mobile Method". If you can't move a complete method, create a mobile method using the "Shuang Method". Finally, you can use the "Hiding Method" on these SET and GET methods.

------------------------------------------ from: "Areca_chen.tw date: MON Jun 3, 2002 9:03 Amsubject: Refactoring Reading Note 4-21

Refuse bequest [Reflections: Subcategories are not used in the parent category all the contents are very common, so this problem is not very big, unless you just want to use the parent category, do not want to practice the front of the parent category This is a real problem. ]

Subcategories inherit all data and methods from the parent category. But if he doesn't want it, don't you need? Then he only takes it. Traditionally, this means that the inherited level architecture is wrong. You need to create a new brother (SIBLING) and use the "Movement" and "Fail Down" to move all the way to the brothers. This way is only a common part of the parent class. So you often hear the recommendations of "all super category should be abstract". The odor refusing to reject the herit is not very strong, and it doesn't mean that you have always paid attention to this odor. It is only to say that traditional recommendations are followed by traditional recommendations when there is trouble or problem that has caused trouble or problems.

The biggest problem caused by this odor is that when the child category is inherited, but it is not willing to support the interface of the parent class. It is not to refuse to reject the interface. Don't mess with the inherited level architecture, you need to use the "Entrusted Replace Hierarchy".

------------------------------------------ from: "Areca_chen.tw date: MON Jun 3, 2002 9:06 Amsubject: Refactoring Reading Note 4-22

Comments [Thinking: The annotation is not odor, just annotation pointing out smell. The most important thing is that the name of the method can explain what this method is doing. Also your method can't be too big to make full expressive meaning. ]

This smell is not to say that you don't write. Note is often guided by a bad code. When you reorganize these bad program, you will find an annotation at all. When you want to use the annotation order code, try "quenching methods". If you need to annotate the code code after quenching, use "Method Renname". If you need to prompt some "brought breaks" when you need to have the required state.

When you feel that you need an annotation, try the reconnection code to make any annotations become extra.

The time to use the annotation is when you don't know what to do. In addition, what happened, the annotation can explain which is you uncertain. The annotation should explain why you do this, this information is very helpful for future maintenance, especially for forgetting.

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

New Post(0)