EJB design patterns in the application of (1)
EJB design patterns in the application of (1)
What is the Design Mode
Is a design pattern was repeated use, most people know, after cataloguing, code design experience summed up. In order to use the design model is reusable code, the code more easily understood by others and ensure reliability of the code.
There is no doubt that design has on others in the system are win-win, designed to enable the preparation of the code really works, the design model is the cornerstone of software engineering, as a block masonry buildings like.
GoF "design mode" is the first model will be designed to enhance the level of theory, and the standardization, and the book made 23 kinds of basic design since, in the object-oriented software reuse in the development of new a large number of design patterns continue to emerge.
Design patterns and framework
Now, reusable object-oriented software system is now generally divided into three categories: Application Kit and Framework (Framework), we usually are the development of specific software applications; belonging to the Java API Toolkit, and a framework a particular type of software reuse design of a group of mutual collaboration category. EJB (EntERPrise EntERPrise JavaBeans) is a Java application framework for enterprise computing.
Usually defined framework for the overall structure of classes and objects, and so on the relationship between the design parameters, in order to achieve specific application can focus on specific details of the application itself. Records of the main framework of common software applications in the design of decision-making framework emphasizes design reuse, it is necessary to design the framework of the use of design patterns.
In addition, the design patterns contribute to the understanding of structural framework, the framework is usually ripe for the use of a variety of design patterns, if you are familiar with these design patterns, there is no doubt that you will quickly grasp the structure of the framework of our general contact with developers if suddenly EJB J2EE framework, and so will find particularly difficult to learn and difficult to master, then turn to master design model, is to analyze your J2EE EJB or a weapon system.
EJB Design Patterns in the
Below we look at the design point of EJB What is the framework? Prior to this assumption that you have probably learned about the design patterns. Specialized design pattern I see on the design of the model series.
EJB is adopted multi-storey structure, the original development is basically our database applications (commercial logic) direct call database-driven, in EJB for the business logic and database completely separate calculation, the use of a number of structural models: model and Bridge Adapter mode. do so obviously there are three benefits:
1. Separation of the business logic layer and data access layer;
2. Will be able to support multiple databases;
3. Database type replacement, but will not design to the large number of business logic code revision.
EJB in the database will be called (as a select, and other statements) called session bean (Sessionbean), and will be a corresponding database as a record bean entity bean (Entity bean); from these two types of bean completion of the database visit.
And the general session bean is one-to-one client applications, and database and is closely-linked entities bean, in the EJB entity bean (or directly in the session bean), and between the use of the database model and Bridge Adapter mode, and has no intention of the entity bean additional layer between the database, known as DAO (Data Access Object), the DAO is actually a mixture of design patterns.
We Java in the Catalog of pet shops example, is devoted to pet shops in the pet category, in the database access, there are two main processes: CatalogEJB and CatalogDAO, we look at the specific code is how design patterns applications.
Adapter Model Bridge mode and we first see CatalogEJB code:
Public class CatalogEJB implements SessionBean (
Protected CatalogDAO dao;
/ / DAO access to a factory in DAO This is called plant (factory) model an example of public void ejbCreate () (
Try (
CatalogDAOFactory.getDAO dao = ();
)
Catch (CatalogDAOSysException se) (
Debug.println ( "Exception getting dao" + se);
Throw new EJBException (se.getMessage ());
)
)
….
)
We have found that in CatalogEJB not in the usual session bean operation of the database as a ".. select from." Operations such as SQL statements such as these have been packaged into a concrete realization of DAO (Concrete class).
Catalog this example in the use of design patterns Bridge model is a model determine whether, based on the types of participants and their mutual relations, we first look at the definition of Bridge mode and participants: (To be continued)
Tags: EJB, the design pattern






