- Spring 5 Design Patterns
- Dinesh Rajput
- 306字
- 2021-07-08 09:59:25
Using the power of the POJO pattern
There are many other frameworks for Java development that lock you in by forcing you to extend or implement one of their existing classes or interfaces; Struts, Tapestry, and earlier versions of EJB had this approach. The programming model of these frameworks is based on the invasive model. This makes it harder for your code to find bugs in the system, and sometimes it will render your code unintelligible. However, if you are working with Spring Framework, you don't need to implement or extend its existing classes and interfaces, so this is simply POJO-based implementation, following a non-invasive programming model. It makes it easier for your code to find bugs in the system, and keeps the code understandable.
Spring allows you to do programming with very simple non Spring classes, which means there is no need to implement Spring-specific classes or interfaces, so all classes in the Spring-based application are simply POJOs. That means you can compile and run these files without dependency on Spring libraries; you cannot even recognize that these classes are being used by the Spring Framework. In Java-based configuration, you will use Spring annotations, which is the worst case of the Spring-based application.
Let's look at this with the help of the following example:
package com.packt.chapter1.spring; public class HelloWorld { public String hello() { return "Hello World"; } }
The preceding class is a simple POJO class with no special indication or implementation related to the framework to make it a Spring component. So this class could function equally well in a Spring application as it could in a non-Spring application. This is the beauty of Spring's non-invasive programming model. Another way that Spring empowers POJO is by collaborating with other POJOs using the DI pattern. Let's see how DI works to help decouple components.
- LabVIEW入門與實(shí)戰(zhàn)開發(fā)100例
- AngularJS深度剖析與最佳實(shí)踐
- UML+OOPC嵌入式C語言開發(fā)精講
- Web全棧工程師的自我修養(yǎng)
- Full-Stack Vue.js 2 and Laravel 5
- Mastering Apache Maven 3
- 精通MATLAB(第3版)
- Unity 2D Game Development Cookbook
- Android項(xiàng)目實(shí)戰(zhàn):手機(jī)安全衛(wèi)士開發(fā)案例解析
- Java零基礎(chǔ)實(shí)戰(zhàn)
- UML2面向?qū)ο蠓治雠c設(shè)計(jì)(第2版)
- 深度探索Go語言:對象模型與runtime的原理特性及應(yīng)用
- Python應(yīng)用與實(shí)戰(zhàn)
- SQL Server on Linux
- .NET應(yīng)用架構(gòu)設(shè)計(jì):原則、模式與實(shí)踐