XML Oriented vs Annotation oriented programming
What is XML Oriented programming ? – In this approach every application have one or set of documents associated with it. This xml documents contain application configuration information which are defines application’s run time behavior. It is very easy to maintain frequently changing configurations setting using xml document.
What is Annotation Oriented Programming ? – Annotation oriented programming language leverage active code generation with the use of declaration tags embedded within the application source code to generate any other kind of source code, configuration files etc.
XML vs Annotation
1. XML duplicates a lot of information like class, method name etc. But annotation are part of class it self so no duplication of information. For example
web.xml
<servlet>
<servlet-name>DemoServlet</servlet-name>
<servlet-class>demo.servlet.DemoServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DemoServlet</servlet-name>
<url-pattern>/servlet</url-pattern>
</servlet-mapping>
Annotation Approach
@WebServlet(name="DemoServlet", urlPatterns={"/servlet"})
public class DemoServlet extends HttpServlet {
//......
2. Less Robust due to duplication of information which introduces multiple point of failure. Annotations are more robust because annotation are processed with source code.
3. XML is more flexible since processed separately from the code. Annotation are less flexible.
4. XML can express complex relationship and hierarchical structures. Annotation can hold only a small amount of configuration information.
5. For XML, there is no need of access to source code. Annotation can not be used if you don’t have access to source code.
Which one to use ? – Annotations are suitable for most application needs. XML are more complex and can be used to address mode advance issues. XML document can be used to override default annotation values.
The decision is go with annotation or xml depends on architecture behind the framework.
Nice article. Although development and deployment is easier with annotations, am not convinced how will it fare when it comes to long term maintenance. Any configuration change now would mean touching the code.
ReplyDelete