Java basic design open-source framework

Source: Internet
Author: User

Let's take a look at the basic design of various Java frameworks! :)

I, Hibernate Part1. Briefly describe the similarities and differences between hibernate ing inheritance and ing composition? Ing inheritance relationships: In addition to associations and aggregation relationships, classes and classes can also have inheritance relationships. When do we need to map inheritance relationships? For example, a company has employees of different types who share common attributes, it can be placed in an employee class, while the employee's personality (in different places) can be placed in the Child class of the employee class. When ing the employee class, you need to use the discriminate keyword to map the employee type, the subclass keyword is used to map the child classes of empoyee. Ing components: some classes are composed of several categories. For example, a customer may have residential and office addresses, and each address has the same attributes, therefore, you can abstract an address class when ing the customer class to achieve more fine-grained ing. When ing the composition, you must use the component keyword to map the attribute class. 2. What is the significance of the lazy attribute during hibernate ing? First, when hibernate loads objects, all object-related information needs to be read by default. In this way, subsequent applications can directly access these values.
In this way, if A is associated with B, C; then B and C will be installed. If B is also associated with D, E, F. Then D, E, F will also be installed. If the object is not well designed, it is easy to draw pictures, and everyone is associated with each other, the information dragged in will be very huge, or even a simple information may be read, and the entire database will be dragged in. This will naturally cause system crashes, poor performance, and other problems. This problem is serious even if it is well designed. Therefore, lazy is required. Lazy indicates that you do not need to load it for the first time. 3. Please provide some suggestions for optimizing hibernate. 1. Do not put all the responsibilities on Hibernate and refactor the code to reduce database operations, avoid using in operations in database queries as much as possible, and avoid recursive queries. The code quality and rationality of the system design determine the level of system performance. 2. When querying large data volumes, use List () or iterator () to return query results with caution. Instead, use hql for on-demand query. 3. In a one-to-many, many-to-one relationship, using the delayed loading mechanism will enable initialization of many objects during use, which can save memory space and reduce database load, in addition, if the set in the Po is not used, the interaction between databases can be reduced to reduce the processing time. 4. The number of interactions with the database is the most important factor determining the processing time for new, modify, or delete operations on large data volumes or queries on large data volumes, reducing interactions is the best way to improve efficiency. Therefore, during the development process, set show_ SQL to true to gain an in-depth understanding of the hibernate processing process and try different methods, this improves efficiency. II, Spring Part1. What is IOC and how many injection methods does IOC have? IOC refers to control inversion, or dependency injection. Control inversion refers to the way in which dependent objects are obtained. Any important system requires at least two Cooperative Classes to complete the business logic, in general, each object is responsible for obtaining its cooperation object, which leads to a high degree of code coupling, difficult to test, difficult to maintain, and difficult to expand. When IOC is used, the object dependency is provided by the external entity of each object in the coordination system when the object is created. This means that the dependency is injected into the object and the object is decoupled, what is AOP? Does AOP affect performance? AOP-oriented programming. Traditional OOP can avoid code duplication. However, sometimes we cannot use OOP to avoid code duplication or use OOP to get an elegant solution, such as transactions, security, and exceptions, almost every method in our program will deal with them. Is there any way, just like in EJB, to talk about modularity in these aspects. When AOP emerged, it decomposed the system into aspects and concerns, rather than objects. It modularized the problem of cross-cutting in a more general way, thus increasing the degree of modularization of the program. For example, if some methods in our system require security checks, security checks are an aspect for us. We can intercept a certain entry point for these security check methods, then inject the notification to put the security check code (notification) into a function, instead of filling the security check code everywhere. AOP implements interception through the reflection mechanism, which affects the performance, but the impact on the performance is not very serious compared with EJB. Therefore, we should pay attention to the granularity when using AOP. We recommend that you do not use AOP 3 in a very fine-grained manner, and briefly describe how spring manages hibernate transactions? Like EJB, spring also provides declarative transaction support. Spring uses a callback method to extract real transaction implementations from the code, it can use the transaction management support of JTA or the transaction support provided by the hibernate mechanism. In addition, you can also use AOP to extract transaction management from a dedicated Transaction Manager for management. 4. Briefly describe how acegi is implemented: authenticate the identity based on the database. To verify the identity of a customer, acegi must first create a users table and authorities table in the database. acegi will use a JDBC Dao to search for username and password in the users table based on the information entered by the customer, if the information entered by the customer is correct, acegi searches for the permissions of the customer in the authorities table to complete the authentication. 3, JSF Part1. Briefly describe how JSF implements page Jump. First, configure a page Jump rule in the bacingbean configuration file in the JSF configuration file <navigation-Rule>, <navigation-Rule> contains a <from-View-ID> and a series of <navigation-case>. <From-View-ID> indicates the current page, and <navigation-case> indicates the pages where some columns may jump. When a method in the backingbean returns a string, it matches <from-View-ID> based on the current page. If the current page is found, then, the returned string matches the strings contained in the <from-View-ID> tag in the <navigation-case> series, after a matched string is found, the page specified by <navigation-case> is displayed. 2. Briefly describe how to extend the validators in backingbean. Define a verification method in backingbean, such as namevalidator (), and set it in the validator attribute of the JSF input component. For example,

Iv. System Design1. Draw a UML class diagram of the DAO mode and briefly describe the principle and applicability of the mode. DAO mode. Data Access varies depending on the data source. The access to persistent storage (such as databases) varies greatly depending on the storage type (relational database, object-oriented database, files, and so on) and vendor implementation. In addition, sometimes we need to deploy different databases in our project. Therefore, we can use the DAO mode in these cases. If we want to implement this policy for three different types of databases, we can consider adopting the abstract factory design model. suppose. this factory has created a series of Dao for customerdao, accountdao, and orderdao, which applies the implementation of factory methods in the factory class generated in the abstract factory. as shown in:


 

2. As shown in the following source code, usermanager and accountmanager depend on each other. Public class usermanager {accountmanager = new accountmanager (); public user searchbynameuser (string username) {...................} public void dosomeuserthings () {long id = ........ accountmanager. searchaccountbyid (ID );........................}} public class accountmanager {usermanager = new usermanager (); Public Account s Earchaccountbyid (long ID ){..............} public void dosomeaccountthings (){........................ string username = "Tom"; usermanager. searchbynameuser (username );........................}} (1) Is this a good design? If Spring IoC is used, please explain the reasons. (2) re-design the system (no code is required) and describe it using a UML class diagram. (1) The accountmanager and usermanager classes are mutually dependent on each other. The two classes are coupled with each other. when instantiating one party, the other party must be instantiated. This will result in circular dependency and infinite dependency. An error will be reported when the program is running. If IOC is used, spring does not know who will initialize first and reports an error (2) solution: When you need to build a sub-system with a hierarchical structure, use the facade mode to define the entry points of each layer in the subsystem. If the subsystems are mutually dependent, you can make them communicate only through the facade, thus simplifying the dependency between them.
The class diagram is as follows:

3. Design question: permission management for a system. The business rules are as follows (1). The entire system (including multiple modules) has an administrator who can manage the permissions of the entire system; (2) Each module has its own administrator, the administrator of this module can only manage the permissions of this module. (3) An administrator can manage multiple departments at the same time. (4) The administrator cannot view data, but can only view the File status. Employees can view the data and file status. (5) mutual transfer is allowed between the Administrator and the Administrator, and between the Administrator and common employee.

Use the UML tool to design a simple management system as follows:

The class diagram is as follows:

The departmentmanager Class records the management relationships between administrators and departments. The authorities class defines different permissions owned by different roles. For example, employees can read files and administrators can view file statuses. Employeeactorlog: defines the role of an employee.

4. Anne's pet hut has 12 cages, each of which can hold different animals, but only one or zero, including cat, dog, and Snake. use the UML tool to design a simple management system that can add or remove pets in cages and query the type of pets in each cage (including the case where the cages are empty ), count the type and quantity of pets in the cage.

Class Diagram-use case diagram: coopmanager is a management class that manages animals in cages.

 

5. Discussing jsh development experience (jsh: JSF + srping + hiberante) describes the jsh projects that you have participated in, as well as their roles in the projects. Based on the actual jsh project you have participated in, let's talk about your understanding of the jsh project.

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.