Spring, Hibernate decoupling method and design pattern (1)

Source: Internet
Author: User
Tags anonymous

Spring, Hibernate decoupling method and design pattern (1)
1, Spring Resource and the policy mode of different sub-categories (such as: Urlresource, Classpathresourse ...) Implement methods (policies) in the same interface (for example: Resource), different subclasses implement different implementations of the method. Then implement an intermediate class based on the different subclasses of the injection, invoke different subclasses of the same name method, the policy caller through the intermediate class using different policies. The separation of policy callers from different policies enables callers to use different policies flexibly.
2. Spring hibernetcallback and Command mode can implement most common operations (such as database curd operations) by means of a tool-like hibernatetemplate (such as the spring). If there are some more specific actions in my application, How to extend the plate is better, both to maintain the versatility of the template and to take into account flexibility. We design a method in the template this method parameter is an instance of an anonymous implementation class (such as the Hibernatecallback interface) that provides different implementations of the anonymous implementation class (such as implementing different doinhibernate) when invoking the template method. Through this third-party Anonymous implementation Class (command) Implementation of the generic method of the class and the separation of the specific method, better maintain the universality of the class.
3, Hibernate lazy load and proxy mode if a class consumes resources, just implementing the class but not using it is very cost-effective, we can design an intermediate class for this class, the intermediate class is to determine whether the application needs to implement the class when the need for resources, do not need to implement the class , that is, the caller invokes the specific resource consumption class through the intermediary Class (proxy), and realizes the separation of the caller from the resource.

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.