我的编程空间,编程开发者的网络收藏夹
学习永远不晚

A Look Inside J2EE Patterns(4) (转)

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

A Look Inside J2EE Patterns(4) (转)

A Look Inside J2EE Patterns(4) (转)[@more@]

On the fourth day of J2EE Patterns, our journey continued through the Business tier and onwards into the web tier. The first hour of class was spent completing the Service Locator (EJBHomeFactory) lab. The labs were proving to be challenging and Owen was actively assisting students who were deteRmined to get their code successfully compiled and deployed. Day 4 was an interesting class, with the morning spent discussing The Business Delegate Pattern and Mvc architecture. In the afternoon, we moved on to J2EE Web Patterns and the struts framework.

XML:namespace prefix = o ns = "urn:schemas-microsoft-com:Office:office" />

The Business Delegate Pattern

The problem that the Business Delegate pattern solves is the tight coupling between the client and EJBs or JMS destinations. This tight coupling reduces the separation of roles between client programmers and server side component programmers and ultimately results in client side code that must know how to access EJBs and include exception and error handling code.

The Business Delegate pattern solves this problem by creating a layer of delegation that communicates with EJBs and takes care of exception and error handling all on behalf of the client. The Business Delegate may also cache results from the server side that the client may need. For testing purposes, the delegation layer may simulate logic or generate dummy data. The Business Delegate also helps with reusability in that the EJB access and exception handling code that comprise it, are now reusable across multiple clients accessing the same EJBs.

The class was excited to jump right into the Business Delegate lab. In terms of patterns, we were now approaching the 'final frontier' of Business tier patterns that bordered on the Web tier. In fact, the whole purpose of this lab was to decouple the two tiers. In the Business Delegate lab, which still dealt with our web-based game application, we had to implement a GameSystem Delegate which would hide the details of EJB object interactions. Because we would be wrapping the business delgate, we were required to provide some additional functionality such as caching player eMail addresses and providing some log in validation.

After the lab, Owen drew a UML diagram on the board and made us identify all the patterns that were being used in the system. It was a small test to see what all we had learned over the past three days. Pointing to various parts of the diagram, he randomly asked students to identify the pattern being used. "DAO" shouted one, "Session Facade" shouted another, "Command Pattern" exclaimed a third. All correct. We had made Owen proud. A more sensitive instructor would have shed a tear of joy. Before being able to use patterns, it made sense that we should know their vocabulary, and be able to immediately identify them.

"Hopefully, patterns will simplify your design and decouple the layers of your system, isolate changes between the layers and encapsulate variations," Owen reminded the class.

MVC

Looking out from our 11th floor window onto Broad Street, you could see the sunlight creeping in through the buildings and shimmering on the pristine sidewalk. Between the buildings, you could catch a glimpse of the deep blue East river, flowing calmly on a mild October morning. The view outside the window was pure artistry: a clean separation of city, river, and sky.

In order to achieve reusable and extensible software, it is essential to separate the View from the Logic that creates the View. When a new feature needs to be added to the GUI, it should be unnecessary to modify more than the View. The goal of the MVC pattern is to decouple the view (the presentation layer) from the model (the business layer) and have a controller that coordinates between the two.

MVC solves the problem of tightly coupled code in which changes to either the user interface or business logic impacts code from either the model, or the view, respectively. A pure servlet code solution results in difficult to maintain classes that embed HTML within Java code; conversely, a pure JSP solution embeds Java code inside HTML, which produces ugly, hard to understand and maintain web pages.

The solution is to isolate the view to JSP and HTML, isolate the controller to Servlet code, and isolate the model to all Java classes containing nothing web-centric. On one of the slides we looked at a ControllerServlet class and studied its service method in which the request object is examined and directed to an appropriate JSP page based on its session information and what type of page it's trying to access. In this example, the Servlet acted like a gatekeeper and controller to our application, preventing any unauthorized access to classified information.

Your Friendly Neighbourhood J2EE Pharmacy

During break, I spoke to Brian Hanuska who does WEBLOGIC consulting for a Pharmeceutical firm. I asked him how is company is making use of J2EE technologies and what motivated him to take the Patterns course.

"We currently have a search application that is using Convera's Retrievalware indexing tool to allow us to do cross repository searching. It utilizes JNI. We are about to expose the search tool as a Web service throughout the company. To do this we will have to create a connector so that the app is compliant with the J2EE spec (EJB's can not invoke JNI for security reasons). This system would be suited for refactoring through the use of patterns and antipatterns (it's implementation is itself an antipattern).

One of our applications is used to track clinical trials and it utilizes the Struts framework. It talks to Documentum, and a bunch of databases. It employs container managed persistence, container managed relationships, voice XML, SSB, SFB, and many others. It is a load balanced, clustered system (6 WLS servers in the cluster).

Another application is a protein analysis database. This system uses JMS to distribute the processing of work required for research that can lead to new drugs. This system saves a great deal of time for the researchers. It also has a Web front end for the users to submit the proteins, and to check on the results as they are processed, since the results take a long time to process.

I took this course to better learn how patterns can be applied in our company, so that we can continue to create reusable components. Also to explain what patterns were chosen and why a pattern was chosen over another similar pattern."

When we got back from the break, Owen was joking about how developers are generally lazy when it comes to trying to fix problems with their code. They'll try to recompile their code several times (without making any corrections), hoping that things will somehow just fix themselves. He told us a joke to illustrate the point.

"A manager, an engineer, and a developer are going down a hill in a jeep when it suddenly loses control and goes into a ditch. They each attempt to offer a solution to the problem. The manager says 'Let's have a meeting to discuss a solution'. The engineer says 'Let's diSASsemble the jeep, and examine every part to find out where the problem is.' The developer says, 'Let's push it back up the hill and try again.'

J2EE Web Patterns and Struts

Within J2EE applications, MVC is not specific enough to provide tactical coding principles. Decisions still need to be made on where to place JNDI lookup code, data access code, security checks and View routing information. We looked at several Web tier patterns that address some of these issues such as the Front Controller, the View Helper, the Composite View, and the InterceptingFilter Pattern. These patterns are usually used in concert with one another.

The Front Controller acts as a centralized controller that routes all incoming requests; it decides what other objects to use when building the request. Some requests require the use of the model and can benefit from the use of a View Helper that encapsulates accessing that model.

Usually used with the Front Controller, the View Helper further separates the view from the model. It encapsulates model accessing logic within a separate class allowing the view to be completely shielded from the model implementation.

The Composite View is a conglomerate of several smaller views, usually involving use of the 'include' statement. Information regarding which files are included where and when can be diSCOvered through the use of properties files and a View Mapper component. The Composite View pattern allows for the reuse of view components such as headers, footers, animations and login dialogues.

Another interesting Web tier pattern we looked at was the InterceptingFilter Pattern, which is included in the J2EE Servlet api (2.3). This pattern encourages the application of individual filters to a request so that it is easily routed and processed within its proper context. You can reuse and reorder your filters depending on the needs of your request object. Examples of InterceptingFilters are Security Filters, Validation Filters, and even I18nFilters if your Web application supports internationalization.

Towards the latter part of the afternoon, we looked at Struts, an open source framework that enables rapid Java Web application development utilizing a 'Pull MVC' architecture, a Front Controller, a View Helper, and the DTO. Struts is designed to be used in the Web layer of a J2EE application. Through the use of frameworks (such as Struts) and components that are largely generated from existing data sources, the developer is left with much less code to write, debug, document, and maintain. Struts is well established and based upon existing standards and being an open source framework, it is maintained and improved upon by a savy and motivated community of programmers.

Our study of Struts included a look at the ActionServlet (the Controller), which, amongst other things, serves to bundle and route HTTP requests to specific Action classes and JSPs as mandated by the configuration file. The Model in Struts is embodied by Java Beans and ActionFoRM classes. The importance was emphasized of ensuring that business logic within classes is decoupled from the Struts framework for greater reusability, so that it is possible to switch to an alternate view and framework in the future if the need arises.

The View in Struts is embodied by JSP pages and Servlets as well as non-Java web resources such as XML and HTML pages. A rich set of taglibs is associated with the Struts framework and can aid in building complex views. Struts JSPs also provide formatting and error handling capabilities. We examined the struts-config.xml file that described the Action and ActionForm classes used in a sample application. We then looked at the ApplicationResources.properties file that contains instructional text messages for the user, error pages, and text for headings and titles. Owen walked us through the source code of various Action classes and JSP files to show us the dynamics of Struts, and how the three layers, namely, the Model, the View, and the Controller, communicate and interact with one another.

The Home Stretch

On the final day of J2EE Patterns, we attempt to tie everything together and apply all that we learned in the past week. Some of the topics we cover on the last day of J2EE Patterns are the Webwork open source framework and Antipatterns. We also engage in a 'Pattern Hatching' exercise and later split up into groups to apply the patterns we learned in the final lab.


免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

A Look Inside J2EE Patterns(4) (转)

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

A Look Inside J2EE Patterns(4) (转)

A Look Inside J2EE Patterns(4) (转)[@more@]On the fourth day of J2EE Patterns, our journey continued through the Business
2023-06-03

A Look Inside J2EE Patterns(2) (转)

A Look Inside J2EE Patterns(2) (转)[@more@]The second day was an unseasonably hot day for the month of October. The class
2023-06-03

编程热搜

  • Python 学习之路 - Python
    一、安装Python34Windows在Python官网(https://www.python.org/downloads/)下载安装包并安装。Python的默认安装路径是:C:\Python34配置环境变量:【右键计算机】--》【属性】-
    Python 学习之路 - Python
  • chatgpt的中文全称是什么
    chatgpt的中文全称是生成型预训练变换模型。ChatGPT是什么ChatGPT是美国人工智能研究实验室OpenAI开发的一种全新聊天机器人模型,它能够通过学习和理解人类的语言来进行对话,还能根据聊天的上下文进行互动,并协助人类完成一系列
    chatgpt的中文全称是什么
  • C/C++中extern函数使用详解
  • C/C++可变参数的使用
    可变参数的使用方法远远不止以下几种,不过在C,C++中使用可变参数时要小心,在使用printf()等函数时传入的参数个数一定不能比前面的格式化字符串中的’%’符号个数少,否则会产生访问越界,运气不好的话还会导致程序崩溃
    C/C++可变参数的使用
  • css样式文件该放在哪里
  • php中数组下标必须是连续的吗
  • Python 3 教程
    Python 3 教程 Python 的 3.0 版本,常被称为 Python 3000,或简称 Py3k。相对于 Python 的早期版本,这是一个较大的升级。为了不带入过多的累赘,Python 3.0 在设计的时候没有考虑向下兼容。 Python
    Python 3 教程
  • Python pip包管理
    一、前言    在Python中, 安装第三方模块是通过 setuptools 这个工具完成的。 Python有两个封装了 setuptools的包管理工具: easy_install  和  pip , 目前官方推荐使用 pip。    
    Python pip包管理
  • ubuntu如何重新编译内核
  • 改善Java代码之慎用java动态编译

目录