MVC Architecture ideas

Source: Internet
Author: User

From the beginning of J2EE development to the present, many architectures have been developed. The architecture is basically divided into web, service, Dao, entity, and layer-by-layer dependency, every time you write a function module, you must create at least four levels of classes.
Recently, I began to organize some of my own architectures and get some inspiration from a colleague. He hoped to develop the architecture quickly and use it as common as possible. So I also integrated this idea into the architecture, which is roughly as follows:
Data operations can be divided into two types: one is to bind an object, and the other is not to bind an object, that is, the method is common to different entities.
Bound entity:
Similar to the previously used architecture principle, entity is abstracted in the DaO base class so that each subclass of Dao must correspond to only one entity, here, the DaO base class can be obtained through generics, annotations, or abstract methods. However, entity is used to perform common operations such as adding, deleting, modifying, and querying, if the DaO subclass only needs to specify the corresponding entity, these methods of the base class can be used. The service is similar to the web layer. The service is bound to Dao and the Web is bound to service, common Operations such as adding, deleting, modifying, and querying are implemented in the base classes of each layer. For a general module, only the base classes of these four layers must be created to inherit the classes separately, in general, you do not need to override the methods of the base class. In this way, a module has a corresponding Code In addition, there are few other classes of code.
Entity not bound:
Write the DaO base class. Unlike the previous one, you do not need to specify the corresponding entity in this Dao subclass. The base class also writes common methods, then, each method can pass in the Entity class object or entity class through the parameter to know which entity is being operated. In the method implementation, the entity information is obtained through the input parameter, the information can include the primary key of the entity, the corresponding table, and SQL statements used to determine whether the entity exists in the database;
Compile the service base class. This base class depends on a common DAO class to implement common and common methods and pass the entity from the method parameters;
Compile the base class of the web layer, rely on a common service class, write some common methods, however, the service method needs to input entity class or class object, then, I bind the web layer to entity. Each web layer class needs to be bound to an entity class, which can also be achieved through generics, abstract methods, annotations, and other methods.
In this way, the general functional module only needs to write a separate entity and web, and the Web binds the entity, and then uses the common service and Dao, the web layer has some common methods, generally, the addition, deletion, modification, and query functions can be used in a general sense, and only two classes are required for a module. However, if some special functional methods need to be written, you can write a separate service and Dao to inherit the base class, and then implement or override the method to implement this special function.

In this case, I just thought of the idea of such an architecture. You can select SSH or write it on your own for specific frameworks and technologies. Of course, the thought aspects are also very limited. The thought should also be suitable for some small management projects.

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.