In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I would like to talk to you about the mistakes that Java programs are most likely to make. Many people may not know much about them. In order to make you understand better, the editor has summarized the following for you. I hope you can gain something according to this article.
1.Duplicated Code
Code repetition is almost the most common odor. He is also one of the main targets of Refactoring. Code duplication often comes from the programming style of copy-and-paste. OAOO corresponding to him is an important symbol of a good system.
2.Long method
It is the legacy of traditional structure. A method should have the intention of being independent and should not put several intentions together.
3.Large Class
A big category is that you give too much responsibility to one class. The rule here is One Class One Responsibility.
4.Divergent Change
The rate of change of content in a class is different. Some states change once an hour, some change only once a few months, some states change for this reason, while others change for other reasons. Object-oriented abstraction is to separate the relatively constant from the relative change. Isolate one side of the problem from the other. This makes these relatively constant can be reused. Each aspect of the problem change can be reused separately. The coexistence of different changes makes reuse very difficult.
5.Shotgun Surgery
This is just the opposite of the above. Changes to one part of the system involve related changes in many other places. These states and behaviors with similar rates of change and content should usually be placed in the same class.
6.Feature Envy
The purpose of an object is to encapsulate states and behaviors that are closely related to those states. If the methods of one class frequently use the get method to access the state of other classes for calculation, then you should consider moving the behavior to the class with the largest number of states involved.
7.Data Clumps
Some data usually play in groups like children: they appear together in member variables of many classes, in the parameters of many methods, and perhaps they should form objects on their own.
8.Primitive Obsession
Object-oriented novices are usually used to using several primitive types of data to represent a concept. For ranges, for example, they use two numbers. For Money, they represent it as a floating point number. Because you do not use objects to express concepts that exist in the problem, this makes the code difficult to understand and makes it much more difficult to solve the problem. A good habit is to extend the primitive types that the language can provide, using small objects to represent scope, amount, conversion rate, zip code, and so on.
9.Switch Statement
Constant-based switch statements are the enemy of OO, and you should turn it into a subclass, state, or strategy.
10. Parallel Inheritance Hierarchies
The parallel inheritance hierarchy is a special case of shotgun surgery. Because when you change a class in one level, you have to change the parallel subclasses of another level at the same time.
After reading the above, do you have any further understanding of the mistakes that Java programs are most likely to make? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.