The essence of Struts2 technical insider reader's pen record framework

Source: Internet
Author: User

The essence of Struts2 technical insider reader's pen record framework
This book is mainly used by Lu Zhou. < > Book. Unless otherwise stated, the pictures used in the notes are taken from the books.

What is a framework? Why should we use the framework? What does the framework bring to us?
These problems are simple and complex. It is simple because the framework exists in the software design. It is complicated because the framework we are using, whether spring or struts, has been undergoing many years of development and is already very complex internally, therefore, it is not that simple to say a framework clearly in one sentence.
Okay. Since the existing frameworks are complex, let's look for a simple one:

If (str = null | str. length () = 0) {//... your logic}
The above code is simple in both syntax and function: judge whether a string is empty.
Let's take a closer look at the java code we wrote. First, we need to get java syntax support and basic function api support (for example, the str. length () above is the length of the returned string ). In other words, the code we write depends on one of the most basic conditions:
Api support provided by jdk ***
If a requirement is repeated for 1000 times, we need to repeat 1000 times of solutions to the requirement. If we have 1000 items in a project, we need to judge whether the string is empty. Of course, the code above is acceptable, but can we refactor it a little bit?
public abstract class StringUtils{    public static boolean isEmpty(String str){        return str.length()==0 || str==null;    }}
Use the above functions in our Code. The Code is as follows:
If (StringUtils. isEmpty (str) {//... your logic}
We made a small improvement to the code, but this improvement gives our code two good qualities:
1. Readability
As long as you have learned English, you should know what empty means. For the function of "determining whether the string is null", we abstract a method called isEmpty. Isn't it just known? I believe some experienced programmers can think of the internal implementation process when they see the isEmpty method name. Let's take a look at the code before reconstruction. If we are in a 700 or 800-line code snippet, the part of the code we first wrote won't cause a pause in our thinking. The latter, as a refined method, gives us an intuitive reminder.
2. scalability
This is simpler. If you change the function of "determining whether the string is null", you need to change the method 1000 times, instead, extract the logic and synthesize a new method, you only need to change it once.

In fact, the above problem, many computer predecessors have foreseen, in the Apache common-lang.jar there is similar code. If you want to use Apache's Function Extension, you only need to add the jar package above to CLASSPATH.
The above principle is simple and everyone has done it. But this simple example tells us a profound truth:
Every time we add a jar package to CLASSPATH, we get all the additional support for jdk in jar.

The internal structure of all our programs is as follows:
Vc7Sw8fL + crsz6S1xL/assets/nswmc1tcrdteftu1bbve1_0lxeoam8yni + CjxpbWcgc3JjPQ = "http://www.2cto.com/uploadfile/Collfiles/20141226/20141226084343176.jpg" alt = "\">
Therefore, we can draw a conclusion:
The framework is just a jar package, and its essence is to extend the functions of jdk.

So why should we add the jar package to CLASSPATH? In retrospect, our initial intention is:
Solve the difficulties encountered in the development of a certain field.


Therefore, the significance of the Framework is as follows:
Is to solve the problem in a certain field.
Therefore, for our programmers, we should never learn the framework for the purpose of learning the framework. We should learn the framework with an attitude to solve some problems.

This article is just a warm-up. Let's talk about some basic web development knowledge ".

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.