Compiling frameworks in Java (4) -- Annotation vs XML

Source: Internet
Author: User
Looking at the beginning of the development of programming languages, it was just the encapsulation of functions,
In the OO language, the object has its own attributes and methods.
In the age when the framework was full, these attributes and methods had their own attributes to tell the framework how to provide services for itself. For example, Spring and EJB3, POJO uses configuration information to tell the framework to provide non-invasive services (such as transactions) and dependency injection.
The entire process is very natural. The languages that programmers use to describe the system are getting more and more detailed. Therefore, Annotation was enthusiastically sought after when it was launched. Those lightweight frameworks like it, and the AOP solution like it. Even EJB3 puts the treasure on it.
However, the framework already exists before annotation, but at that time we put the information in XML, in the database, and in the attributes of POJO.
In the Spring vs EJB3 article, Spring uses XML and EJB3 use annotaion. However, xml and annotation both have obvious disadvantages, spring and EJB3 both quickly absorb the advantages of another configuration method. For example, Spring supports the use of annotation to declare transactions.
Basically, this advantage is his weakness.
Advantages of Annotation
First, you do not need a strong Factory class to maintain XML configuration information. You do not need to locate the configuration information in the xml file, so you can perform instant reflection quickly.
Second, you do not need to split the configuration file and POJO. Maintenance personnel do not need to open the xml and pojo files at the same time and locate the location of xml information.
However, Annotation also has vulnerabilities.
First, compilation is required and cannot be dynamically updated.
Second, you really need to split the POJO and configuration information, and do not want the configuration information to dirty the POJO.
The third is Hibernate, Struts, three aunts, and four aunts. If the annotation of all the brains is piled up on the poor POJO, the Anontation would be even worse if all the three aunts and six aunts are robbed of the Transation.
Fourth, the XML Processing Association is complex. During nested connections, the expression capability is better than that of annoation.
It can be seen that Annotation has emerged as a lightweight framework favorite for the moment. You should make a trade-off based on your own project.

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.