By James Carman, JavaWorld.com, 07/18/03
down to business
Achieve implementation transparency for your business objects with the Business Object Factory framework
By James Carman, JavaWorld.com, 07/18/03
Many architects strive to reduce coupling between the presentation tier and the business logic tier in multitier applications. The Business Delegate design pattern (in Sun Microsystems' Core Java 2 Platform, Enterprise Edition (J2EE) Patterns Catalog) was created to solve this problem. But, many critics claim it is an unnecessary added layer of abstraction for achieving this simple goal. Most argue that the business delegate's interface mimics the business logic interface so closely that any change to the business logic interface also mandates a change to the business delegate's interface. In most cases, this is true. However, the Business Delegate pattern has other benefits such as remoteness hiding, failure recovery, thread synchronization, and caching. But many applications that use the Business Delegate pattern do not take advantage of these additional benefits. Thus, the pattern's overhead seems to outweigh its merits. For these applications, all that is desired is an abstraction layer that hides the underlying implementation details, such as the familiar lookup and narrow operations required for Enterprise JavaBeans (EJB) implementations. This article takes you through the API, configuration, and implementation of one such framework, the Business Object Factory framework.
许多架构师致力于在多层程序中减少表现层和业务层的耦合.因此业务代理设计模式被创建出来用以解决这个问题.但许多批评意见认为这是一种为达成简单目的而不必要添加的层.
Note: You can download this article's source code from Resources.
The API
The Business Object Factory framework's simplest part is the API itself. There is only one major class, but a few other "behind-the-scenes" classes can extend and customize the framework.
The BusinessObjectFactory class
Apart from the business interfaces used in their applications, consumers of business objects' services need only concern themselves with one primary class, BusinessObjectFactory. Let's look at its public interface:
public final class BusinessObjectFactory
{
public BusinessObjectFactory getInstace();
public Remote create( Class businessInterface );
}
As you can see, the BusinessObjectFactory class implements the Singleton design pattern (a Gang of Four design pattern). The BusinessObjectFactory's constructor is declared as private, and the class only maintains one static instance. This provides one global point of access to the functionality BusinessObjectFactory provides. We could just as easily make all of the methods static, but that approach is more object-oriented.
The create() method tends to raise a few eyebrows. First, it returns an instance of java.rmi.Remote. Most business object implementation choices, namely Remote Method Invocation (RMI), EJB, and the Java API for XML-based Remote Procedure Calls (JAX-RPC), require a remote interface. For simple JavaBean-based business object implementations, this adds the inconvenience of requiring the client code to catch java.rmi.RemoteException when it will never be thrown. However, this inconvenience helps provide the implementation transparency, as the business objects can be migrated to a different implementation type without altering the client code. The only stipulation is that the remote interface does not change. Another create() method peculiarity is its parameter type, java.lang.Class, which corresponds to the remote interface type requested. This allows the BusinessObjectFactory class to be loosely coupled with the application using it. This does not prevent company XYZ from creating an adapter class to simplify client programming: Continued
--------------------------------------------------------------------------------
Related Article1 | 2 | 3 | 4 | 5 | Next >
Discuss
Start a new discussion or jump into one of the threads below:
Subject Replies Last post
Configuration file Schema
By Katari 0 02/20/07 03:14 PM
by Katari
Singleton
By Juan Casares 2 03/02/06 09:33 AM
by Anonymous
Interesting, but very tilted towards EJB usage
By Eric Pugh 4 03/01/06 07:04 PM
by Anonymous
Oops...
By James Carman 0 08/05/03 09:17 PM
by Anonymous
Print E-Mail article Feedback Add to del.icio.us Related Article Resources
Download the source code that accompanies this article
http://www.javaworld.com/javaworld/jw-07-2003/factory/jw-0718-factory.zip
Business Delegate pattern in Sun's Core J2EE Patterns Catalog
http://java.sun.com/blueprints/corej2eepatterns/Patterns/BusinessDelegate.html
Browse more of Sun's Core J2EE Patterns Catalog
http://java.sun.com/blueprints/corej2eepatterns/Patterns/
The famous Gang of Four bookDesign Patterns, Eric Gamma, Richard Helm, Ralph Johnson, John Vlissides (Addison-Wesley Publishing Co., 1995; ISBN0201633612)
http://www.amazon.com/exec/obidos/ASIN/0201633612/javaworld
The Apache Software Foundation's Commons Digester homepage
http://jakarta.apache.org/commons/digester
"Simplify XML File Processing with the Jakarta Commons Digester," Erik Swenson (JavaWorld, October 2002)
http://www.javaworld.com/javaworld/jw-10-2002/jw-1025-opensourceprofile.html
The Apache Software Foundation's Commons Logging homepage
http://jakarta.apache.org/commons/logging.html
The Apache Software Foundation's Commons BeanUtils homepage
http://jakarta.apache.org/commons/beanutils.html
The AspectJ homepage
http://www.aspectj.org
AOP- and AspectJ-related articles in JavaWorld:
"I Want My AOP," Ramnivas Laddad:
Part 1Separate software concerns with aspect-oriented programming (January 2002)
Part 2Learn AspectJ to better understand aspect-oriented programming (March 2002)
Part 3Use AspectJ to modularize crosscutting concerns in real-world problems (April 2002)
"Add a JAC to Your Toolshed," Renaud Pawlak (March 2003):
http://www.javaworld.com/javaworld/jw-03-2003/jw-0307-jac.html
Sun's Java Servlet Technology homepage
http://java.sun.com/products/servlet/
Jason Hunter's JavaWorld articles about Servlet 2.3 discuss the servlet filter model:
"Servlet 2.3New Features Exposed" (January 2001):
http://www.javaworld.com/javaworld/jw-01-2001/jw-0126-servletapi.html
"Filter Code with Servlet 2.3 Model" (June 2001):
http://www.javaworld.com/javaworld/jw-06-2001/jw-0622-filters.html
Also read about the latest Servlet 2.4 specification in Jason Hunter's "Servlet 2.4What's in Store" (JavaWorld, March 2003)
http://www.javaworld.com/javaworld/jw-03-2003/jw-0328-servlet.html
For more servlet-related articles, see the Servlets section of JavaWorld's Topical Index
http://www.javaworld.com/channel_content/jw-servlets-index.shtml
Read David Geary's Java Design Patterns columns
http://www.javaworld.com/columns/jw-java-design-patterns-index.shtml
For more design pattern articles, visit the Design Patterns section of JavaWorld's Topical Index
http://www.javaworld.com/channel_content/jw-patterns-index.shtml
Browse the Enterprise JavaBeans (EJB) section of JavaWorld's Topical Index
http://www.javaworld.com/channel_content/jw-ejbs-index.shtml
Browse the Java 2 Platform, Enterprise Edition (J2EE) section of JavaWorld's Topical Index
http://www.javaworld.com/channel_content/jw-j2ee-index.shtml
Browse the Java and XML section of JavaWorld's Topical Index
http://www.javaworld.com/channel_content/jw-xml-index.shtml
Speak out in the JavaWorld Forum
http://www.javaworld.com/javaforums/ubbthreads.php?Cat=&C=2
Sign up for JavaWorld's free weekly email newsletters
http://www.javaworld.com/subscribe
Partner Content
Open Source Software Solutions
Explore a universal platform of frameworks for open source on eclipse solutions coming on April 5, 2007.
Continuum of open source
Build Secure Web Services
Discover how to authenticate using a user ID and password, ensure integrity using digital signatures, and ensure confidentiality using encryption.
Build your services now
Rational V7 Downloads
Test-drive the IBM Rational V7 desktop products offering new capabilities for empowering global teams to speed SOA results.
Free Rational trials
New! Rational SOA Testing Open Beta
IBM Rational invites you to participate in our open beta program for testing SOA applications.
Sign up today!
Sponsored links
JUnit Test Generation
Submit Java. Get back FREE JUnit. Try it! - www.junitfactory.com
Java Installer Builder
install4j is easy to use, amazingly powerful and creates beautiful installers for all platforms. Try out the free trial version. - ej-technologies GmbH
Buy a link now.Cost Effective SOA Management & Runtime Governance
JaxView SOA Management for small to medium enterprise Management and Policy enforcement. Try it Now!
Free Webinar: The IT infrastructure of the future
Learn about how the HP BladeSystem is revolutionizing the datacenter. Attend the free webinar here.
The comprehensive, yet seamless help desk solution
Apply ITIL best practices at your service desk while eliminating integration cost. Learn more here.
RESEARCH CENTERS: Java Standard Edition | Java Enterprise Edition | Java Micro Edition | Development Tools
About Us | Advertise | Contact Us | Terms of Service/Privacy
Copyright, 2006-2007 Network World, Inc. All rights reserved.
IDG Network: CIO Computerworld CSO Demo Games.net IDGconnect.com Infoworld IT World Canada Linuxworld.com Macworld NetworkWorld.com Outsourcing World PC World Playlistmag.com
