What is the framework? (Best Practices)

 
Original link: https://mp.weixin.qq.com/s/En7nC2cjVeNI_vLjr4nYTg

Transfer: Code AGRICULTURAL stand (Micro Signal: coderising)

Zhang determined to embark on big fat Java Road, Great God listened to Bill's advice, first learned Java SE, the Basics collection, threads, reflection, IO, generics, annotations, like school again, under strict supervision and in Bill's write a lot of code.

Then began to learn Web-based, what Http, html, javascript, css, servlet, jsp, tomcat ... but also a lot of knowledge. He on the Internet for a small site, with its own analog to do a bit, though not professional artists, interface terrible, but he was imitating the function of 7788, great sense of accomplishment.

Taipan take the matter to Bill looked, Bill praise: "ah, the function can also be implemented without any frame can be made this way, very good."

Taipan said: "? What is the framework framework?"

Bill froze for a moment: "You suddenly asked me to live, we have all day opening frame, closed frame, now let me give a definition framework, I really can not tell, let me think."

Bill eyes closed, waiting for a big fat piety.

Less than a stick of incense effort, Bill opened his eyes: "I'll give you an example, you are not just a servlet and jsp made small Web projects do, assuming you do to make someone pay for a similar system, you how would you do? "

"Then I put the code now copy it, to change to change on it, you do not have to?"

"If there are eight or ten like this project it, do you have to do it by copying and pasting?" Bill asked

"Eight or ten? I still go jumping off a building."

"Then you do not think to repeat some of the things which extracted to form what may be reusable?"

Taipan Zhang said: "Listen you say, there is really something you can reuse, say URL mapping and business code, I often encounter like this url: www.xxx.com?action=login, servlet in the background, I would judge, if the name of action is login, I put userName, password such parameters extracted from the form out, perform the login code. I have to write a lot of if else to support different business logic, very grueling. sometimes I thought, if there is a way to directly to the URL and the Java classes directly mapped up like so much easier! "

"Yes, this is a good idea, and you?" Bill asked, smiling.

"Ah ah ... Another example is data validation, such as login user name or password wrong, I want to display an error message on the browser side, this is difficult to do ah, error of fonts, colors, icons, location too annoying a. "

"And you?"

"Yes, access to the database is a big problem, I write a lot of SQL, JDBC code a lot, just to get the data from the database into Java objects go. You know for sure, have to deal directly with JDBC programming many details: Always remember to close the connection, and the handle exceptions ... and so on, tell you the truth, I copy and paste the code is a lot of. "

"Can not you write a generic class, passing SQL, returns a result set it?" Bill asked.

"Then I must have written, but the result set to become a Java object there is still a long way too, lacks technical content, pure manual labor, no wonder people call us code farmers!" Taipan said angrily.

Bill said: "I just flipped through your code, I found a lot of places are not great people, like you almost all the business logic written Servlet the go, but also among those who doping control and jump pages , such a mess like spaghetti code over a month estimate you just could not understand. "

Taipan embarrassed laugh: "No month, which just over a week I Fan Yun."

"So well, in fact, you would have these problems we encountered predecessors, they are also trying to explore, constantly looking for better ways to achieve the future to find the experience to put all kinds of curing down, called best practices ."

"Best Practices? Well give me an example!"

"For example, there is a good Web development practice ah, called MVC. Is mixed with the solution proposed above for your business logic and page control. This practice would strongly suggest that you put the data model, the page display, page Jump to write separate control, prevent stir into a ball. "

Bill enough, continue Example: "Another example of the first question you said, there are also long been the solution, you can use XML or Java annotations to describe the relationship between the URL and the Java classes, you only need to declare it, behind operations are handed over to the framework to deal with. there are correspondence between your Java objects and database tables, only need to declare it, the frame can help you get it out, filled into a Java object to, which greatly It reduces your workload. "

"Bill, you also mentioned the framework of the word, can you say, like a template framework, inside has some pre-accepted best practice, if I want to use it, my project-related things go on filling it, is not it? "

"It can be understood, like a frame semi-finished products, can not be run independently, it must be defined in accordance with the rules, the project code is placed by the developer to the place designated by the integrating framework, this is a complete application. "

A key generating function code frame based SSH

Taipan scratching his head and said: "? That framework Actually no, ah, I just understand those best practices, to master its rules, not learned yet."

"Yes, a lot of Java Web-based systems are like SpringMVC, Hibernate, the popular frameworks such as construction MyBatis up, the framework had to learn, but if you only use frames, only filling the code, it is just a HTML fill in the blank staff . "

"Then I finished school framework, the framework can be used to do the project, and to learn what's next?" Taipan was a little not the end.

“你要是对Java 后端编程感兴趣, 还有很多东西啊, 用框架实现了业务只是很小一块, 还有系统架构设计, 缓存、性能、高可用性、分布式、安全、备份等很多内容啊, 你学的越多,就会发现无知的领域更多, 所谓学无止境啊!”

张大胖目视远方,沉默了。。。。。

Guess you like

Origin www.cnblogs.com/skycto/p/11470069.html