What is the biggest pursuit of software?

Source: Internet
Author: User
During this time in the open-source field, spring 2.0 will support non-anemia models. That is to say, the persistence of the domain model can be fully implemented in the domain model itself, this is an exploration of object-oriented technology. For Domain Model Modeling confusions, see here.

When object-oriented technology is binding model object persistence behavior to model data itself, the SOA promoted by the Industry advocates decoupling data from behavior. For more information about SOA, see here. Seemingly contradictory. Actually, they have one thing in common and 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.

The following is a detailed example:CodeIt means that "adding new things" and "organizing these things" belong to different levels of knowledge. Some people only think about software.AlgorithmAnd the data structure, think that these are science, in fact, this is the software mathematical, software is not just a scientific computing tool, it is also a science, more like management/economics, it is a combination of science and art.

Published an article on the recently published Java (TM) boutique websiteArticleMeasuring the complexity of OO systems, which measures the complexity of OO systems. This article describes several well-known truths about software complexity. If you do not study and train these principles, even if you use such tools as OO language Java, it still shows that you are "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

WhereNumber of demo-pointsIt refers to a condition judgment statement such as if else. For example, it is the following statement:

Public void isvalidsearchcriteria (searchcriteria s ){

If (s! = NULL ){
Return true;
} Else {
Return false;
}
}

Cyclomatic complexity has a great impact on the Code testability and maintainability, as shown in the previous example, when you want to testIsvalidsearchcriteria () 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 Status mode/policy mode of the gof design mode (are you still using the if else ).

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 ){

DataaccessmanagerManager = new dataaccessmanager ();
AuditmanagerAuditmanager = new auditmanager ();
// Save the registration
Manager. saveregistration (regdata );
// Audit the creattion
Auditmanager. createauditrecord (regdata );

}

Public Registration findregistration (string regnumber ){

DataaccessmanagerManager = new dataaccessmanager ();
Registration Reg = NULL;

// Find the registration
Reg = manager. findregsitration (regnumber );

Return reg;

}

}

This classRegistrationmanagerDependent on the other two classesDataaccessmanagerAndAuditmanager.

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

In this way:RFC (registrationmanager) = 2 + 2 + 1 = 5

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 thatDataaccessmanagerAndAuditmanagerMethods in the class are defined to the currentRIn the egistrationmanager class, you will get a high value of WMC, which indicates that this class needs to be reorganized.

Loosely Coupled 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 programming is not proud (may come from nature), and learning how to organize is the true profession.ProgramMember.

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.

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.