Java programming: What is the biggest pursuit of software?
Source: Internet
Author: User
Java programming: What is the biggest pursuit of software? -- Linux general technology-Linux programming and kernel information. The following is a detailed description. During this time, there are two things worth noting in the Java World: the industry promotes SOA; in the Open Source Field, Spring 2.0 will support non-anemia models and push OO programming to a new stage.
No matter the launch of the new SOA architecture or the continuous development of OO, they all pursue the same ultimate goal: loose coupling.
When we struggle in the waves of Java, we often think? Why am I doing this? Even, we want to be loose and cool? Is maintainability really the only software? Maybe we are lost.
What is the greatest pursuit of software?
Our college computer education only teaches us how to program? This is like teaching students in a technical school how to use lathes. When we learn programming, what is next? Isn't it? Is it just like a car mechanic who needs to program repeatedly day after day?
In fact, when you continuously program in a system (adding new things), the system becomes complicated and the biggest challenge you face is how to sort out your own products.
That is to say: university education only teaches us how to "Add new things", but does not educate us how to "organize these things". The latter is the new impetus for the ever-changing revolution in the software field.
Next we will use specific code to explain that "adding new things" and "organizing these things" are completely different levels of knowledge. Some people will only think of algorithms and data structures when talking about software, we think that this is science. In fact, this is to matalize software. software is not only a tool for scientific computing. It is also a science, just like management/economics. It is a combination of science and art.
A recent article published on the Java (TM) Boutique website, Measuring the Complexity of OO Systems, to measure the Complexity of OO Systems. This article describes several well-known principles of software Complexity in detail, if you do not study and train these principles, even if you use such tools as OO language Java, you will still be "amateur.
Software Complexity includes the following parts (derived from Measuring the Complexity of OO Systems ):
* Cyclomatic Complexity (circle Complexity)
* Response for Class (Class Response)
* Weighted methods per class (each class Weight Method)
Cyclomatic Complexity
The following code describes Cyclomatic Complexity:
Cyclomatic Complexity (CC) = number of demo-points + 1
Here, number of demo-points refers to a condition judgment statement such as if else. For example, it is the following statement:
Public void isValidSearchCriteria (SearchCriteria s ){
Cyclomatic complexity has a great impact on code testability and maintainability. As mentioned in the previous example, when you want to test the isValidSearchCriteria () method, you must write three test cases to verify it.
If this CC value increases, more judgment points will be available, which means more effort is needed to test these methods. For more information, see the article Measuring the Complexity of OO Systems.
Therefore, conditional statements such as if else or while are harmful to true OO (for non-OO principle, see Thomas McCabe). It can be said to the extreme: A good OO system can hardly see the if else and other judgment statements that exceed two or more conditions at the business logic layer. These condition statements can be replaced by the GoF design mode, such as the State mode and Policy mode.
When your Java System is filled with a large number of if else statements, although you use a cool language tool, it means that your thinking is a traditional process and requires re-learning and training.
Response for Class (RFC)
This is one of the famous Chidamber and Kemerer principles. See the following code:
Public class RegistrationManager {
Public void createRegistration (RegistrationData regData ){
DataAccessManager manager = new DataAccessManager ();
AuditManager auditManager = new AuditManager ();
// Save the registration
Manager. saveRegistration (regData );
// Audit the creattion
AuditManager. createAuditRecord (regData );
}
Public Registration findRegistration (String regNumber ){
DataAccessManager manager = new DataAccessManager ();
Registration reg = null;
// Find the registration
Reg = manager. findRegsitration (regNumber );
Return reg;
}
}
The RegistrationManager class depends on the DataAccessManager and AuditManager classes.
According to the principle formula:
RFC = M + R (M = number of methods in this class. R = Other total)
In the preceding example, the number of RFC class responses is as follows:
Number of methods in RegistrationManager = 2
Number of methods that call DataAccessManager = 2
Number of methods that call AuditManager = 1
When a class and many other classes have dependencies, it becomes complex and even difficult to modify and maintain. In this way, the larger the RFC value, the worse your system tastes.
Of course, because OO systems are based on classes and methods, it is impossible to develop a zero-value RFC system, but our goal is to achieve a balance. when you design an OO system, always pay attention to these principles and try to avoid class encoding reaching a high RFC value.
If we use modern models, such as the Ioc model, we can easily achieve such a balance without effort. Therefore, using frameworks such as Spring and Jdon is a shortcut to reduce the RFC value.
Weighted methods per class
The previous several principles explain how to use interactive calls between classes to make the software system abnormal and complex. A system or a specific class itself will become abnormal and complex, and there are many methods, the Weighted Method Per Class principle helps us to quantify and define these situations.
The definition of this principle is based on two situations: one class implementation and different implementations.
WMC 1 = number of all methods in a class.
WMC 2 = number of Cyclomatic Complexities of all methods.
No matter which formula you choose, a WMC high value shows that this class may need to be reorganized into multiple classes.
This formula helps you keep the class clean and more close to the relevant behaviors (cohesive ).
The previous RFC example shows that if you define the methods in both the DataAccessManager and AuditManager classes to the current RegistrationManager class, you will get a high value of WMC, which indicates that the class needs to be reorganized.
Good Software Design
We have mentioned refactoring over and over again in the previous chapter. It means that you will not only "Add new things", but also learn to "sort these things ).
Just like a child playing with toys, he can quickly learn to play with a new thing without a teacher. However, when he finishes playing with many new toys, it is hard for him to sort out the toys he has lost everywhere. It can be seen that learning to program is not proud (may come from nature), and learning how to organize is truly a professional programmer.
Now, let's go back to the essence of the problem. The above lists the complexity of the software, and the complexity will lead to difficulties in maintenance and testing. So we need to sort out the software. Can we quantify the degree of organization?
We use the concept of "loose coupling" to express the degree of ease of maintenance, easy to test, and easy to expand. Of course, the higher the loose coupling value, the easier maintenance of our system. At present, the development of the software world, SOA, Ioc/AOP are not all pursuing the maximization of loose coupling?
Loosely Coupled is an antonym of "tightly coupled". Since we learned to play programming, we have two options: it is a simple, training-free, almost natural "tightly coupled" route, and a "loosely coupled" Road trained by science. The path you choose depends on whether you have received professional training.
Therefore, for programming, this toy is not about whether you can play, but about how you play it? Playing level. If you do not understand the truth, China's software slump will never end.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service