focusengineering Internet software

Objects and the Web

Alan Knight, Cincom Systems Naci Dai, ObjectLearn

pplying software engineering principles, particularly object-ori- ented techniques, to the Web can be difficult. Many current Web technologies lend themselves to—or even encourage—bad prac- A tices. Scripting and server-page technologies can encourage cut- and-paste reuse, direct-to- coding, and poor factoring. Component models such as the Component Object Model (COM) and Enterprise Java- Beans (EJB) seek to construct building blocks for application assembly, but in doing so they sacrifice many of the advantages of objects. XML emphasizes

technology-independent reuse and sharing the need for these techniques, we examine of content, data, and messaging but at the some representative Web technologies and expense of encapsulation and the associa- the issues they present in naive use. We de- tion of behavior with state, which is central scribe a layered, OO architecture, based on to OO. the Model-View-Controller (MVC) pattern, Scripting languages, common on the which can overcome these issues to produce Good design Web, are often optimized for rapidly creat- large, well-structured systems. ing simple functionality rather than for practices are Motivations increasingly modular construction of large programs. Also, such languages typically lack the rich If we consider scripts from an OO and important in Web development environments of general-pur- layering perspective, the most immediate development. Here, pose languages. Some Web developers even problem is that a single script has responsi- the authors apply deliberately disregard software engineering bilities spanning several layers (see the “Def- such practices principles. They argue that if we’re just initions” sidebar for an explanation of our using a framework writing scripts, they don’t merit the kind of terminology). The script must for layered engineering techniques—object or other- architectures based wise—we apply to “real” systems. Accept input on the GUI However, software engineering and OO Handle application logic development pattern techniques are gaining importance in Web Handle business logic of Model-View- development as Web applications become Generate output (presentation logic) Controller. more complex and integrated with tradi- tional server-side applications. To motivate This couples all the layers together, making

0740-7459/02/$17.00 © 2002 IEEE March/April 2002 IEEE SOFTWARE 51 Authorized licensed use limited to: Universidad Federal de Pernambuco. Downloaded on June 18,2010 at 23:56:58 UTC from IEEE Xplore. Restrictions apply. Definitions

Here we define our terminology and goals. In the main text, ing business functionality. This code should be entirely unaware we present a layered architecture, implemented using both scripts of the presentation being used. We also refer to business ob- and server pages. Most of these techniques can be applied to jects, which implement the business logic. In a complex appli- any technology in these categories, but where the details of a cation, business logic is likely to be the largest component and specific technology are important, we use servlets and Java- can include code that accesses external systems such as data- Server Pages as representative technologies. Both, while nomi- bases, external components, and other services. In the Model- nally Java specifications, can easily be applied to other lan- View-Controller framework, this corresponds to the model. guages, and implementations in both Smalltalk and C++ are commercially available. Presentation This layer contains code and noncode resources (such as Layered architecture HTML text and images) used to present the application. It typi- A layered architecture is a system containing multiple, cally contains little code—code concerned only with formatting strongly separated layers, with minimal dependencies and in- and presenting data. An example of this in a Web context is a teractions between the layers. Such a system has good separa- server page’s code fragments that print values into a dynami- tion of concerns, meaning that we can deal with different areas cally generated Web page. In the Model-View-Controller of the application code in isolation, with minimal or no side ef- framework, this corresponds to the view. fects in different layers. By separating the system’s different pieces, we make the software adaptable so that we can easily Scripts change and enhance it as requirements change. The layers we Many basic Web technologies can be grouped together in are concerned with here include input, application logic, busi- the category of scripts—small programs that perform HTTP pro- ness logic, and presentation. cessing. This term encompasses, among others, compiled CGI programs, files of scripting language code (such as Perl, Input Python, Ruby, and VBScript), and Java servlets. While there are The input layer contains the code concerned with processing significant differences among these technologies, all of them and syntactically validating input. In a Web context, this pro- have the fundamental characteristic of being programs that ac- cessing and syntactically validating input includes HTTP input cept an HTTP request and send back a response. In basic us- parsing and extracting parameters from an HTTP request. In the age, each script is stateless and independent of all others. An Model-View-Controller framework, this corresponds to the input important distinction within this category is whether scripts can controller. share memory with other scripts (for example, servlets) or are entirely independent (for example, CGI programs). Shared Application logic memory allows more effective use of system resources through The application logic code is concerned with the applica- pooling, and a simpler programming model through persistent tion’s overall flow. We often refer to it as the glue layer, sepa- states at the cost of a more complex infrastructure. rating business logic from input and presentation logic and managing the interface between the two. This requires some Server pages knowledge of both layers. For example, this layer would be in- An alternative mode of HTML scripting is that of an HTML volved in converting between presentation-level inputs and out- page annotated with small amounts of code. Many scripting lan- puts as strings and the corresponding business object messages guages support this kind of facility in addition to pure scripts, and or state. This layer might also manage a multipage Web inter- representative examples include JavaServer Pages (JSP), Mi- action as a sequence of steps. In the Model-View-Controller crosoft’s Active Server Pages, PHP, and Zope. There are also vari- framework, this corresponds to the application controller. ations on this approach in which the pages are annotated with application-specific HTML or XML tags, and developers can spec- Business logic ify code to be run when these tags are encountered. Examples of The business logic code is concerned only with the underly- this include JSP bean and custom tags and Enhydra’s XMLC.

it harder to modify or test any particular Accepting input aspect in isolation. In addition, there are When accepting input, a script receives ei- significant issues related to handling these ther the raw HTTP input stream or a mini- responsibilities, as described below. For mally parsed representation of it. HTTP sup- server pages used alone, the same issues ap- ports several different mechanisms for ply (because we can consider a server as a passing parameters (encoding into the URL, script with some additional embedded query values, or form data), and all of these HTML), and mixing code with the HTML pass the data as simple strings. Each script also presents code management and debug- must know or determine the parameter-pass- ging issues. ing mechanism, convert the parameters to

52 IEEE SOFTWARE March/April 2002 Authorized licensed use limited to: Universidad Federal de Pernambuco. Downloaded on June 18,2010 at 23:56:58 UTC from IEEE Xplore. Restrictions apply. appropriate types, and validate them. This debug inside complex generated code. For causes code duplication between scripts. these reasons, it is a good idea to minimize the amount of code in server pages and to keep It is a good idea Handling application logic application logic out of the pages. Another issue, which affects both input to minimize the and application logic, is the lack of informa- Handling business logic amount of code tion hiding when accessing request and ses- Because all of the code is grouped to- in server pages sion data. The script must retrieve input data gether, it is difficult to isolate the business from the request by name. HTTP is a state- logic from the other layers, particularly ap- and to keep less protocol, so data used in multiple scripts plication logic. Furthermore, unless we can application logic must be either stored in a session identified run portions of the scripts separately, it is with the user or reread from an external data impossible to test the business logic (or any out of the pages. source in each script requiring the data. For of the other layers) independently. example, if a script passes login information With server pages, business logic presents as form data, the code to store that informa- the same issues that we discussed for appli- tion in the session might be cation logic. We can very quickly have too much code in the pages, and even pages password = request.getParameter with minimal code are difficult to manage (“passwordField”); and debug. decrypted = this.decode (password); Generating output request.getSession().putValue In producing output, simple scripts mix (“password”,decrypted); the HTML encoding of the result with the dynamic data. This couples the page’s look Both storage in the session and storage in and feel with the other layers. Changing the an external data source are effectively global Web site’s look or adapting the application to in scope, and the application accesses them in multiple output devices becomes extremely dictionary-like fashion using strings as keys. difficult. The latter is becoming increasingly Normal programming mechanisms for con- important as the Web expands to include de- trolling variable access do not apply to this vices such as WAP (Wireless Application Pro- data, and any scripts or server pages that wish tocol)-connected mobile phones and other to use this data must be aware of the naming small devices. conventions. We cannot easily find all accesses Server pages help address this last issue by to the variables using programming-language letting Web designers design and maintain mechanisms, so modifications become more the pages and by letting programmers pro- difficult. If the script does not encapsulate vide annotations. This is generally considered these conventions, knowledge of them and of the most appropriate use for server pages. the HTTP protocol’s details can spread throughout the application, greatly hindering Model-View-Controller adaptation to new uses. Furthermore, this is a To overcome these difficulties, we can use potential source of errors because of both a combination of scripts, server pages, and spelling errors and different scripts using the application code. The approach we present same name for different purposes. As the here is part of a family of possible approaches number of scripts or server pages increases, we have used1,2 to properly partition respon- these problems become overwhelming. sibilities and overcome weaknesses in the un- When using server pages for application derlying technologies (see the “A Related Ap- logic, we are adding potentially significant proach” sidebar for a comparison). MVC amounts of code to the page. Code manage- strongly influences our approach, so we first ment techniques are not usually available for examine its history. code inside server pages. With many tech- nologies, debugging code inside the server MVC concepts pages is difficult. Features of modern devel- MVC originated in the Smalltalk-80 system opment environments for code authoring and to promote a layered approach when develop- interactive debugging might not be available, ing graphical user interfaces.3 It emerged in the and for compiled languages we might need to late 1970s and early 1980s, long before such

March/April 2002 IEEE SOFTWARE 53 Authorized licensed use limited to: Universidad Federal de Pernambuco. Downloaded on June 18,2010 at 23:56:58 UTC from IEEE Xplore. Restrictions apply. A Related Approach

There are many frameworks and design patterns influenced input, action, presentation, and model. by layering, the Model-View-Controller pattern, and object Application controller responsibilities are assigned to ac- principles. In general, using servlets and server pages together tions, model objects, or declarative aspects of the framework. and keeping code out of the server pages as much as possible Actions are command objects, and Struts suggests that they is referred to in Java circles as model 2 Web programming should delegate as much behavior as possible to the model, but (see http://java.sun.com/j2ee). The most widely known frame- coding examples include application control or even model be- work using these principles is the open source Jakarta Struts havior in some actions. The transition to the next page after an (see http://jakarta.apache.org/struts). action is controlled by the developer by editing configuration Struts is a controller framework for Java to build JavaServer files. One other difference is that Struts classifies model objects Pages-based views that are linked to business models using a into “bean forms” that have only state, and more normal ob- single controller servlet. Struts is very close to many of our con- jects with both function and behavior. These bean forms are cepts and also uses a single input controller servlet, but it dif- used to store data for input or presentation processing. We fers in some significant areas. Most notably, it does not distin- have no corresponding layer and are unclear as to the role of guish a separate application controller, distinguishing only pure state objects in an OO framework.

state changes to dependents, which were typi- cally views. This is similar to many current Notifications GUI component models, of which JavaBeans Model View is perhaps the most widely known. This scheme provided a good separation Display between these three layers but suffered from two weaknesses. First, it had a simplistic Keyboard, view of the model and did not account for Controller mouse any difference between application logic (for (a) example, flow of control and coordination of multiple widgets in a GUI) and business logic (for example, executing a share pur- chase). Second, most GUI libraries and win- Notifications dowing systems combined the view and con- Application View controller troller functions in a single widget, making the logical separation into view and con- Business Notifications troller less useful. Later versions of Smalltalk objects with operating system widgets chose not to Input use a separate controller. All of the Smalltalk controller versions eventually introduced an additional layer to handle application logic, distinct from the business objects. Perhaps the most Business logic layer Tool layer View layer elegant of these is Presenter, as used in, for example, Taligent and .4,5 Problem space User interface (b) Together, these revisions changed the common understanding of the framework, such that the term controller now refers to Figure 1. (a) The the object handling application logic and original Smalltalk-80 interfaces had become mainstream. It defined the term model is reserved for business ob- Model-View-Controller three different components (see Figure 1a): jects (see Figure 1b). To distinguish these pattern and (b) the two interpretations of MVC, we use model revised Model-View- The model handles application and to refer to business objects, and we use in- Controller. business logic. put controller and application controller to The view handles presentation logic. refer to the two types of controllers. The controller accepts and interprets keyboard and mouse input. MVC for the Web To apply MVC to the Web, we use a com- The intention was to separate the model bination of scripts, server pages, and ordi- (meaning nonGUI) code from its presentation. nary objects to implement the various com- The model code didn’t contain any GUI infor- ponents in a framework we call Web mation, but it broadcast notification of any Actions. In this context, both versions of the

54 IEEE SOFTWARE March/April 2002 Authorized licensed use limited to: Universidad Federal de Pernambuco. Downloaded on June 18,2010 at 23:56:58 UTC from IEEE Xplore. Restrictions apply. WAP WAP input controller MVC are relevant, particularly the dual uses Input of the term controller. For HTTP applica- controller HTTP HTTP input tions, input and presentation are entirely controller separate, so an input controller distinct from the view is useful. For applications of any Finds and executes Application Action complexity, we also need an application con- controller troller to separate the details of application flow from the business logic. Figure 2 shows the framework’s basic ob- XML view XML ject structure. View JavaServer Java- Page view Server Input controller. We implement the input con- Page troller as a script. One of the framework’s important features is that there is a single in- put controller for all pages in a Web appli- cation. The input controller parses input, de- termines the parameter-passing mechanisms, Figure 2. The Web extracts any necessary information from the ject as the central point of reference for any Actions framework. request, cooperates with the application persistent information, the application con- controller to determine the next action, and troller resolves the issues of information invokes that action in the correct context. hiding and naming conventions. Rather By having a single script as an input con- than storing isolated pieces of information troller, we localize any knowledge of HTTP in the session, we store them in business ob- or naming conventions at the request level, jects and access them using messages from reduce code duplication and the total num- the application controller. Programming- ber of scripts, and make it easier to modify language mechanisms let us track use of the any of the input processing, because there is application controller and business objects a single point of modification. and more easily modify our code. If we are Note that the input controller class is using a statically typed language, we also shown as an abstract class, with one imple- get static type checking as an additional val- mentation for accessing the applications idation of data usage. over HTTP with a regular Web browser and another implementation for accessing the Action. The single input controller will in- applications using a WAP-enabled device. voke one of many possible actions on each request. One of its responsibilities is to de- Application controller. We implement the ap- termine which one. This depends on both plication controller as a regular object—not the input from the user and on the applica- as a script or server page. It coordinates tion’s current state, so it must be determined logic related to the application flow, handles in conjunction with the application con- errors, maintains longer-term state (includ- troller. We represent the result of this deter- ing references to the business objects), and mination as an Action object (an implemen- determines which view to display. We store tation of the Command pattern described the application controller in the session us- elsewhere6). ing a key known to the input controller. This relies on a naming convention, with Business objects. We implement business ob- the disadvantages described earlier, but be- jects as normal objects that contain only cause this is the only thing stored directly in business logic, so they should have no knowl- the session, the impact is minimized. edge of any other layers. The application A single application controller is respon- controller is the only thing that manipulates sible for multiple Web pages. In a simple the business objects, and for this reason they application, it might be responsible for all are not shown in Figure 2 but are inside the pages; in a complex application, there are application controller. Both of these attri- multiple application controllers for different butes make it much easier to develop and test areas of the application. the business logic in isolation from the Web By using a single, well-encapsulated ob- infrastructure. Because the business objects

March/April 2002 IEEE SOFTWARE 55 Authorized licensed use limited to: Universidad Federal de Pernambuco. Downloaded on June 18,2010 at 23:56:58 UTC from IEEE Xplore. Restrictions apply. Figure 3. Java code for an input public void service( HttpServletRequest req, controller servlet. HttpServletResponse res ) throws ServletException, IOException {

ApplicationController controller = this.appControllerFor(req); this.setValuesIn(controller, request); String actionID = req.getPathInfo(); Action action = controller.actionFor(actionID); appController.performAction(action); View view = this.viewFor(req); view.forwardPage(controller.nextPage()); }

might be isolated, we should be able to use cation. First, we see how the input con- the same implementation for a thin-client troller accepts input, finds and sets up for Web application, a more rich-client imple- the action, executes the appropriate applica- mentation, or even a traditional GUI. tion controller code, and then delegates to the view. Figure 3 shows sample code for View. We implement views as server pages, this, and here we examine each of the steps. which can access the application controller and business objects. Views should contain as Find the controller little code as possible, delegating most func- The input controller must determine tionality to the application controller or busi- which application controller is responsible ness objects. Only code directly related to for the current request. Active application presentation in the current page should be controllers are stored in the session. We as- used in a page. If supported, we prefer to use sume that we can determine the controller a tag mechanism such as JavaServer Pages using a lookup based on the request’s path. (JSP) custom tags to remove code from the For example, in our banking application, pages altogether. we might have an account maintenance ap- Figure 2 shows two different view mecha- plication controller, which is used for any nisms. The first uses a server page implemen- pages related to account maintenance. tation, appropriate for a Web browser or WAP device. The second generates the same Accept input information in an XML format, which could Once we have determined the application be sent to an applet, an ActiveX control, or a controller, we must extract the appropriate GUI application. information from the request and transfer that information to the application con- Web actions: Control flow troller. Most notably, we need to find any By organizing the scripts, server pages, and input parameters. These can be encoded as regular objects as we’ve described, we’ve over- part of the URL, as query parameters listed come many of the issues associated with sim- after the URL, or as form data. Regardless ple Web development. We have minimized of the transmission mechanism, this input code duplication and reliance on the proto- consists entirely of strings and must be con- col’s details or naming conventions by using a verted into the appropriate types and vali- single input script. We have also achieved dated. The input controller extracts the in- good information hiding by maintaining the formation and, in cooperation with the data in objects rather than as flat session data. application controller, performs basic syn- We have confined our use of server pages to tactic validation and informs the applica- the view layer, maximizing the amount of code tion controller of the values. we can manage and debug using standard pro- For example, we might have a user re- gramming tools and methods. By keeping each quest to transfer funds such as layer separate, we can test each in isolation. Overall, our application remains well-factored https://objectbank.com/ and easy to maintain and extend. InputController/transfer?from= To see how this works in more detail, 123&to=321&amt=$50.00 let’s examine the flow of control from a sin- gle Web request in an online banking appli- The string /transfer identifies the action to

56 IEEE SOFTWARE March/April 2002 Authorized licensed use limited to: Universidad Federal de Pernambuco. Downloaded on June 18,2010 at 23:56:58 UTC from IEEE Xplore. Restrictions apply. the input controller. The remainder of the This lets us separate the different actions, but string holds query parameters for the two ac- it does not give us as much encapsulation in count numbers and the amount to transfer. the application controller as we might like. Keeping code On the other hand, a request to update ac- Rather than the standard OO usage of mul- count holder data might be submitted from tiple methods on a single object, we have and data an HTML form and would carry many pieces many action objects that manipulate the con- together in the of data as form data, invisible in the URL: troller’s state, providing little encapsulation. application As an alternative, we can represent the https://objectbank.com/ action simply as an indicator of the applica- controller InputController/updateAccountData tion controller method to be performed. provides better This is particularly easy in a system such as Find the action Smalltalk, with simple reflection techniques. encapsulation The application controller can keep track Given a Smalltalk servlet and JSP frame- but raises of a set of acceptable sequences of operations work,7 we can simply set the action potential team and the previous steps the user has taken. On the basis of this and the information submit- action := #deposit. issues of having ted in the request, we can determine which ac- many people tion to take and whether this action is legal in and then execute the current context. This logic is particularly collaborating on important because Web users can use the controller perform: action. a single object. Back button to throw off the sequence of op- erations in a way that is not possible in a GUI. In this case, the action is simply the action In the simplest version, we might define method’s name, and we invoke it with the actions for login, logout, transfer between ac- standard perform: method. No action class counts, account update, and bill payments. or trigger operation is necessary. Any account activity is allowed once the user Which of these choices is preferred depends has logged in, but actions transferring money on the situation. Keeping code and data to- have a confirmation page. We only let the gether in the application controller provides user confirm a request if the immediately better encapsulation but raises potential team previous operation was the request. We also issues of having many people collaborating on detect the situation in which the user backs a single object. In a GUI presentation, it might up and resubmits the same request or hits the also be desirable to use the full Command pat- Submit button repeatedly while waiting for tern to better support Undo functionality. the first submission to be processed. Forward the request Perform the action We use forwarding to divide responsibil- Once we have determined which action ity among different components. Once the to take, we must execute it. The exact pro- action is complete, we determine the URL of cedure for this varies depending on which the next page to be displayed and forward implementation we choose. We might the request. In a simple system, the actions choose to have heavyweight actions, imple- can directly determine the next page. In a mented as objects inheriting from a class more complex system, the application con- Action and implementing a trigger method. troller might coordinate this using internal state management such as a state machine. public void trigger(Controller controller){ Variations BankController ctrlr= We have described one particular imple- BankController)controller; mentation of this type of framework. Many Account acct=ctrlr.readAccount others are possible, and in our uses of this (context.getAccountNo()); framework, we have made significant varia- ctrlr.setCurrentAccount(account); tions depending on the application’s precise ctrlr.setNextPage(“account needs. Summary”); } Complex views We have described views as mapping di-

March/April 2002 IEEE SOFTWARE 57 Authorized licensed use limited to: Universidad Federal de Pernambuco. Downloaded on June 18,2010 at 23:56:58 UTC from IEEE Xplore. Restrictions apply. rectly to server pages, but in more complex tion of an action’s results from the action it- applications, this can become more sophis- self. It is also an appropriate place to imple- ticated. First, we can assemble larger views ment functionality such as internationaliza- from multiple smaller views. So, we might tion of the result. have a main page with subsections in frames or with subsections determined by including Action context the results of other Web requests. We could We have described an architecture with model this structure either by explicitly is- very lightweight actions in which state is as- suing new requests or by using an internal sociated directly with the application con- mechanism to forward the request to an- troller. In some situations, it might be useful other partial page. to dissociate some of this state from the We might also want to interpose another controller. In particular, if we do not have a layer of objects at the view level. For exam- simple mapping from the URL to the appli- ple, if handling multiple possible forms of cation controller, we might need to extract output, we might need an explicit View ob- more of the request state to determine the ject that handles the output details on a par- correct controller. We can do this by intro- ticular device. For example, we might store a ducing an ActionContext object, which key that lets the View identify the appropri- stores the request state in a standardized ate output. This might delegate to different form. In this case, we would create the con- server pages for HTML and WAP presenta- text, use it to find the appropriate con- tion and to a screen identifier for a GUI. Us- troller, and then apply actions to the combi- ing a View object helps isolate the presenta- nation of controller and context.

PURPOSE The IEEE Computer Society is the world’s COMPUTER SOCIETY WEB SITE largest association of computing professionals, and is the The IEEE Computer Society’s Web site, at leading provider of technical information in the field. http://computer.org, offers information and samples from the society’s publications and conferences, as MEMBERSHIP Members receive the monthly well as a broad range of information about technical magazine COMPUTER, discounts, and opportunities committees, standards, student activities, and more. to serve (all activities are led by volunteer mem- bers). Membership is open to all IEEE members, COMPUTER SOCIETY OFFICES Headquarters Office affiliate society members, and others interested in EXECUTIVE COMMITTEE 1730 Massachusetts Ave. NW the computer field. President: WILLIS K. KING* Washington, DC 20036-1992 University of Houston Phone: +1 202 371 0101 • Fax: +1 202 728 9614 BOARD OF GOVERNORS Dept. of Comp. Science E-mail: [email protected] Term Expiring 2002: Mark Grant, Gene F. Hoff- 501 PGH Publications Office nagle, Karl Reed, Kathleen M. Swigger, Ronald Houston, TX 77204-3010 10662 Los Vaqueros Cir., PO Box 3014 Waxman, Michael R. Williams, Akihiko Yamada Phone: +1 713 743 3349 Fax: +1 713 743 3335 Los Alamitos, CA 90720-1314 Term Expiring 2003: Fiorenza C. Albert- [email protected] Phone: +1 714 821 8380 Howard, Manfred Broy, Alan Clements, Richard E-mail: [email protected] A. Kemmerer, Susan A. Mengel, James W. Moore, President-Elect: STEPHEN L. DIAMOND* Membership and Publication Orders: Christina M. Schober Past President: BENJAMIN W. WAH* Phone: +1 800 272 6657 Fax: +1 714 821 4641 VP, Educational Activities: CARL K. CHANG * E-mail: [email protected] Term Expiring 2004: Jean M. Bacon, Ricardo European Office Baeza-Yates, Deborah M. Cooper, George V. Cy- VP, Conferences and Tutorials: GERALD L. ENGEL* 13, Ave. de L’Aquilon benko, Wolfgang K. Giloi, Haruhisha Ichikawa, VP, Chapters Activities: JAMES H. CROSS† B-1200 Brussels, Belgium Thomas W. Williams VP, Publications: RANGACHAR KASTURI† Phone: +32 2 770 21 98 • Fax: +32 2 770 85 05 Next Board Meeting: 10 May 02, Portland OR VP, Standards Activities: LOWELL G. JOHNSON E-mail: [email protected] IEEE OFFICERS (2ND VP)* Asia/Pacific Office President: RAYMOND D. FINDLAY VP, Technical Activities: DEBORAH K. SCHER- Watanabe Building President-Elect: MICHAEL S. ADLER RER(1ST VP)* 1-4-2 Minami-Aoyama, Minato-ku, Tokyo 107-0062, Japan Past President: JOEL B. SYNDER Secretary: DEBORAH M. COOPER* Phone: +81 3 3408 3118 • Fax: +81 3 3408 3553 Executive Director: DANIEL J. SENESE Treasurer: WOLFGANG K. GILOI* E-mail: [email protected] 2001–2002 IEEE Division VIII Director: Secretary: HUGO M. FERNANDEZ VERSTAGEN EXECUTIVE STAFF THOMAS W. WILLIAMS Treasurer: DALE C. CASTON Executive Director: DAVID W. HENNAGE 2002–2003 IEEE Division V Director: VP, Educational Activities: LYLE D. FEISEL Publisher: ANGELA BURGESS GUYLAINE M. POLLOCK† VP, Publications Activities: JAMES M. TIEN Assistant Publisher: DICK PRICE Executive Director: DAVID W. HENNAGE† Director, Volunteer Services: ANNE MARIE KELLY VP, Regional Activities: W. CLEON ANDERSON *voting member of the Board of Governors Chief Financial Officer: VIOLET S. DOAN VP, Standards Association: BEN C. JOHNSON Director, Information Technology & Services: VP, Technical Activities: MICHAEL R. LIGHTNER ROBERT CARE President, IEEE-USA: LeEARL A. BRYANT Manager, Research & Planning: JOHN C. KEATON

11-FEB-2002

58 IEEE SOFTWARE March/April 2002 Authorized licensed use limited to: Universidad Federal de Pernambuco. Downloaded on June 18,2010 at 23:56:58 UTC from IEEE Xplore. Restrictions apply. Business logic and components Acknowledgments We have not devoted a great deal of dis- The authors thank Michael Ellis and Martin Fowler for their contributions to the ideas expressed here. cussion to the business logic layer, because we consider it to be a normal OO program. However, it can be quite complex and in- volve any number of other technologies. References One that frequently comes up is the rela- 1. M. Ellis and N. Dai, “Best Practices for Developing tionship between this layer and compo- Web Applications Using Java Servlets,” OOPSLA 2000 tutorial; www.smalltakchronicles.net/papers/Practices. nents, particularly Enterprise JavaBeans. pdf. Some frameworks (when using Java) use en- 2. N. Dai and A. Knight, “Objects versus the Web,” OOPSLA tity EJBs as a standards-based solution for 2001 tutorial; www.smalltalkchronicles.net/papers/ the business object layer. objectsXweb10152001.pdf. 3. E. Gamma et al., Design Patterns, Addison-Wesley, We do not generally consider this to be a Reading, Mass., 1994. good solution. Although the business logic 4. G.E. Krasner and S.T. Pope, “A Description of the Model-View-Controller User Interface Paradigm in the layer might have good reasons for accessing Smalltalk-80 System,” J. Object-Oriented Program- components—most notably session beans en- ming, vol. 1, no. 3, Aug. 1988, pp. 26–49. capsulating access to transactional or legacy 5. M. Potel, MVP: Model-Viewer-Presenter, tech. report, IBM, 1996; www-106.ibm.com/developerworks/ systems—using entity beans to represent the library/mvp.html. business logic seems ill-advised. Entity beans 6. A. Bower and B. MacGlashan, “Model-View-Presenter offer some automation potential for issues Framework,” 2001, www.object-arts.com/Education- Centre/Overviews/ModelViewPresenter.htm. such as transactions, security, and persistence, 7. VisualWave Application Developer’s Guide, tech. re- but they impose serious limits on our design port, Cincom Systems, 2001. and have significant performance constraints, even relative to normal Java performance. In particular, the absence of inheritance is a bur- For more information on this or any other computing topic, please visit our den, and other frameworks exist to deal with Digital Library at http://computer.org/publications/dlib. transactions, security, and performance in the context of normal business objects. Finally, it is harder to test EJBs in isolation because they require a container to run; this imposes in- creased overhead on development. Using ses- sion beans to wrap business objects or forgo- ing EJBs altogether are both reasonable alternatives. About the Authors sing our framework, developers pri- marily focus on writing application Alan Knight is a senior software developer at Cincom Systems, where he works on Smalltalk U code rather than dealing with Web tools. He was also recently the technical servlets, requests, or session variables. We lead on a high-performance Smalltalk Web appli- have used this in a variety of different Web cation server supporting full implementations of ASP, JSP, and servlets. His research interests in- applications, using both Smalltalk and Java. clude Web development, object-relational map- In this, we have achieved better software ping, and team programming systems. He re- quality because good OO principles were ceived his BS and MS in computer science from Carleton University in Ottawa, Canada. He is a member of the ACM. He not dictated but followed naturally from the coauthored Mastering ENVY/Developer (Cambridge Univ. Press, 2001). structure of the framework. Paradoxically, it Contact him at 594 Blanchard Cr., Ottawa, Ontario, Canada K1V 7B8; also allowed developers inexperienced with [email protected]. OO techniques to produce high-quality code Naci Dai is an independent mentor and an without knowing the details of the frame- educator. He teaches object technology, Java, de- work too well. These frameworks could be sign patterns, and distributed computing. He leads and mentors Web development projects. He extended in several different areas, including has a background in applied engineering and customization to particular domains, con- computational physics. He has received his PhD version into a full-fledged framework rather in mechanical engineering from Carleton Univer- sity. He is a member of the ACM. Contact him at than a set of patterns, and more detailed Acarkent C75, 81610 Beykoz, Istanbul, Turkey; adaptation to particular technologies. [email protected].

March/April 2002 IEEE SOFTWARE 59 Authorized licensed use limited to: Universidad Federal de Pernambuco. Downloaded on June 18,2010 at 23:56:58 UTC from IEEE Xplore. Restrictions apply.