MyBatis know how (6) presentation layer and business logic layer

Source: Internet
Author: User

Presentation Layer

The presentation layer is responsible for showing the end user how the application is controlled and how it is data. It also takes care of the layout and format of all information. Today, the most popular manifestation of business applications is the Web front-end, which uses HTML and JavaScript and Web browsers to meet the user's interface appearance needs.

The benefits of Web applications include cross-platform compatibility, ease of deployment, and scalability. Amazon.com is a great example of a Web application that allows you to buy books Online. This is a great application for Web applications because it is not possible to ask users to download an application in order to buy a book.

Web applications are often not competent when advanced user controls or complex data manipulation are required. In these cases, rich clients that use native operating system widgets, such as tab, table, TreeView, and embedded objects, demonstrate the benefits. Rich clients allow a much more powerful user interface, but it is often more difficult to deploy, and it takes a developer more effort to achieve the same level of performance and security as a Web application. Examples of rich-client technologies include the Java swing and so on.

Recently, the concepts of Web applications and rich clients have been mixed to form what is known as "hybrid clients", and "hybrid clients" try to gain the benefits of both Web applications and rich clients. Some of the rich clients that are very small and use some high-level controls may be silently downloaded to the user's desktop through a Web browser. This hybrid rich client does not contain any business logic, and even the layout of the user interface may not be built-in. Conversely, the interface appearance of an application and the available business functions are configured through a Web service or as a Web application that uses XML as a client-server interface. The only downside to this approach is the need for additional software to develop and deploy such applications.

Then of course there is a typical case of the so-called mixed-type presentation layer, Ajax. It used to be the acronym for Asynchronous JavaScript and XML (asynchronous JavaScript and XML), but now everyone realizes that it doesn't need to be asynchronous or use XML, so now Ajax stands for just "a web-based Rich customer interface, driven by a lot of very clever JavaScript. " Ajax is a new way to build a rich and interactive user interface using legacy technologies. Google is a great way to check out Ajax technologies, such as those used in Gmail, Google Maps, and Google Calendar.

MyBatis can be used both for Web applications and rich-client applications, as well as for hybrid applications. Although the presentation layer does not normally "communicate" directly with the persistence framework, some decisions in the design of the user interface will still affect your need for the persistence layer. For example, consider a Web application that needs to process a large list of 5,000 records. We can't need to show all of these 5,000 records at the same time, and it's not a good idea to load these 5,000 records from the database at the same time if we don't need to use them immediately. A better solution might be to load and display only 10 records at a time. In this case, the persistence layer needs to be able to allow some flexibility in the number of returned data, or even provide the ability to select and obtain the 10 records we want. This avoids unnecessary object creation and data acquisition, reduces the network traffic and memory requirements of the application, and thus improves application performance. MyBatis allows you to query only a specific range of data, and such features can help us achieve these goals.

Business Logic Layer

The business logic layer of the application describes the "coarse-grained" services that the application can provide. It is for this reason that classes in the business logic layer are sometimes referred to as service classes. At a high level, anyone should be able to read the classes and methods in the business logic layer and understand what the system is going to do. For example, in a bank application, the business logic layer might contain a class named Tellerservice, which includes methods such as Openaccount (), deposit () withdrawal (), and GetBalance (). These are very large features that involve complex database interactions and may even be interacting with other systems. These methods are too heavy to fit in the domain class, otherwise the code is likely to become coupled immediately and often difficult to manage. The solution is to isolate these coarse-grained business methods from the business object models that are relevant to them. The separation of the business logic class from the object model class is sometimes referred to as the "separation of nouns from verbs".

Pure object-oriented commentators may argue that such designs are not object-oriented, and that the business approach is more object-oriented, directly in the relevant domain classes. Either way more object-oriented, the separation of concerns is a better design choice. The main reason for this is that business methods are often very complex. They usually involve more than one class, and the underlying components that handle more than one base component may include databases, message queues, and other systems. More importantly, a business function often involves many domain classes, so it is difficult to decide which class the method should belong to. It is for these reasons that coarse-grained business functions are best implemented as a method of a class in the business logic layer.

Don't be afraid to put the finer-grained business logic into the relevant domain classes. Those coarse-grained service methods in the business logic layer are free to invoke the fine-grained, purely logical approach built into the domain class.

In our tiered architecture, the business logic layer is the consumer of the persistence layer service. It calls the persistence layer's method to get the data and modify the data. The business logic layer is also the best place for transactional delimitation, as the coarse-grained business functions defined in it can be used by many different user interfaces, and may even be used by some other interface like Web services.

Series Articles:

MyBatis know how much (1)

MyBatis know how much (2)

MyBatis know how much (3)

MyBatis know how (4) The advantages of MyBatis

MyBatis know how much (5) Business object model

MyBatis know how (6) presentation layer and business logic layer

Related Article

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.