⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch08.htm

📁 corba比较入门级的介绍详细间接了corba访问发布各种细节。
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><HTML><HEAD><SCRIPT LANGUAGE="JavaScript"><!--function popUp(pPage) { var fullURL = document.location; var textURL = fullURL.toString(); var URLlen = textURL.length; var lenMinusPage = textURL.lastIndexOf("/"); lenMinusPage += 1; var fullPath = textURL.substring(0,lenMinusPage); popUpWin = window.open('','popWin','resizable=yes,scrollbars=no,width=525,height=394'); figDoc= popUpWin.document; zhtm= '<HTML><HEAD><TITLE>' + pPage + '</TITLE>'; zhtm += '</HEAD>'; zhtm += '<BODY bgcolor="#FFFFFF">'; zhtm += '<IMG SRC="' + fullPath + pPage + '">'; zhtm += '<P><B>' + pPage + '</B>'; zhtm += '</BODY></HTML>'; window.popUpWin.document.write(zhtm); window.popUpWin.document.close(); // Johnny Jackson 4/28/98 }//-->                                                                </SCRIPT>	<META NAME="Author" Content="Bryan Flores">	<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">	<TITLE>Teach Yourself CORBA In 14 Days -- Ch 8 -- Adding Automated Teller Machine (ATM) Capability</TITLE></HEAD><BODY TEXT="#000000" BGCOLOR="#FFFFFF"><CENTER><H1><IMG SRC="../button/sams.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"><BR><FONT COLOR="#000077">Teach Yourself CORBA In 14 Days</FONT></H1></CENTER><CENTER><P><A HREF="../ch07/ch07.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch09/ch09.htm"><IMGSRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <HR></CENTER><CENTER><H1><FONT COLOR="#000077">Day 8<BR>Adding Automated Teller Machine (ATM) Capability</FONT><A HREF="#Heading1"></A></H1></CENTER><UL>	<LI><A HREF="#Heading1">Defining Additional Requirements</A>	<LI><A HREF="#Heading2">Modifying the Class Diagram</A>	<UL>		<LI><A HREF="#Heading3">Two New Classes: ATM and ATMCard</A>		<LI><A HREF="#Heading4">Modifying Existing Classes</A>		<LI><A HREF="#Heading5">Two New Exceptions: AuthorizationException and InvalidATMException</A>	</UL>	<LI><A HREF="#Heading6">Modifying the IDL Specification</A>	<LI><A HREF="#Heading7">Implementing the New Functionality</A>	<UL>		<LI><A HREF="#Heading8">Enhancing the BankServer</A>		<LI><A HREF="#Heading9">Enhancing the Bank</A>		<LI><A HREF="#Heading10">Implementing the ATM Server</A>		<LI><A HREF="#Heading11">Implementing the ATM Client</A>	</UL>	<LI><A HREF="#Heading12">Running the Application</A>	<LI><A HREF="#Heading13">Summary</A>	<LI><A HREF="#Heading14">Q&amp;A</A>	<LI><A HREF="#Heading15">Workshop</A>	<UL>		<LI><A HREF="#Heading16">Quiz</A>		<LI><A HREF="#Heading17">Exercise</A>	</UL></UL><P><HR SIZE="4"><CENTER><H1><FONT COLOR="#000077"></FONT></H1></CENTER><P>On Day 7, you started with the basic <TT>Bank</TT> application and made the firstset of enhancements to it, adding error-checking functionality through the CORBAexception mechanism. The end result was an application with the same basic functionalitythat you implemented on Day 6 but with more robust error handling. Today you'll buildon that same application, adding more features. Specifically, you'll define the interfacefor a virtual Automated Teller Machine (ATM) device and enhance the <TT>Bank</TT>application to interact with this device. The process you'll follow is this:<UL>	<LI><I>Define additional requirements</I>. The original requirements for the <TT>Bank</TT>	application said nothing about ATMs, so you will modify the requirements to define	this new feature.<BR>	<BR>		<LI><I>Modify the system design.</I> Adding ATM functionality will result in a number	of new classes being added to the system. You'll identify these classes in the analysis	and design phase. (Revisiting this phase will reinforce the concept that software	design is an iterative process.)<BR>	<BR>		<LI><I>Modify the IDL definitions.</I> After you have defined the new classes to	be added and have modified some existing classes, you'll create or update the interface	definitions for those classes.<BR>	<BR>		<LI><I>Implement the new functionality.</I> After the design is finished and realized	in IDL, you'll be ready to implement the new functionality and see how the new application	works.</UL><H2><A NAME="Heading1"></A><FONT COLOR="#000077">Defining Additional Requirements</FONT></H2><P>First of all, as a review, recall that on Day 5 you defined the following systemrequirements for the <TT>Bank</TT> application:<UL>	<LI>Supports multiple banks<BR>	<BR>		<LI>Supports multiple accounts within banks<BR>	<BR>		<LI>Supports multiple customers holding accounts<BR>	<BR>		<LI>Supports customers holding multiple accounts<BR>	<BR>		<LI>Supports the capability to open (create) new accounts<BR>	<BR>		<LI>Supports the capability to close (delete) existing accounts<BR>	<BR>		<LI>Supports the capability to enumerate a bank's accounts<BR>	<BR>		<LI>Supports the capability to determine an account's owner(s)<BR>	<BR>		<LI>Supports the capability to withdraw funds from an account<BR>	<BR>		<LI>Supports the capability to deposit funds into an account<BR>	<BR>		<LI>Supports the capability to transfer funds between accounts within a single bank<BR>	<BR>		<LI>Supports the capability to transfer funds between accounts in different banks<BR>	<BR>		<LI>Supports checking accounts (which don't gain interest)<BR>	<BR>		<LI>Supports savings accounts (which do gain interest)</UL><P>The original requirements said nothing about the support of Automated Teller Machines(ATMs). But what if you want to modify the application to support the ATM concept?Certainly it is possible to add this capability to the application; this chapterdemonstrates just how to do this.</P><P>To add ATM capability, you first define a set of requirements that describes exactlywhat functionality is necessary. To support ATM functionality, the requirements mightlook something like this:<UL>	<LI>Supports the capability for a customer to deposit funds into an existing account	through an ATM<BR>	<BR>		<LI>Supports the capability for a customer to withdraw funds from an existing account	through an ATM<BR>	<BR>		<LI>Supports the capability for a customer to obtain the balance of an existing account	through an ATM<BR>	<BR>		<LI>Supports the capability for an ATM to authorize customers through the use of	an ATM card and a Personal Identification Number (PIN)<BR>	<BR>		<LI>Supports the capability for an ATM card to access multiple accounts belonging	to a customer in a particular bank</UL><P>In other words, an ATM provides three basic functions: depositing funds, withdrawingfunds, and obtaining account balances. The ATM is accessed via an ATM card that,in conjunction with the customer's PIN, authorizes that customer to access the account(or accounts) for which the ATM card is authorized.</P><P>Of course, you won't be dealing with an actual ATM; rather, you'll be simulatingthe operation of an ATM through IDL interfaces. The operation of the <TT>ATM</TT>will thus be greatly simplified compared to an actual ATM, which must interface witha cash dispenser, video screen, keypad input, network, and other components. Your<TT>ATM</TT> interface will abstract the entire ATM, assuming that these componentsall work together as a single unit.<H2><A NAME="Heading2"></A><FONT COLOR="#000077">Modifying the Class Diagram</FONT></H2><P>Now that you've identified the requirements associated with providing ATM functionality,you're ready to decide which existing classes in the system need to be modified,which classes need to be added, and what the new classes should do.<H3><A NAME="Heading3"></A><FONT COLOR="#000077">Two New Classes: ATM and ATMCard</FONT></H3><P>Naturally, the expansion of the <TT>Bank</TT> application to include ATM functionalityintroduces some new classes into the system. An obvious class is the <TT>ATM</TT>itself; another class is <TT>ATMCard</TT>--the device the customer uses to identifyhimself or herself to the ATM. Now, take a look at the operations that these classesmust support. Recall that the <TT>ATM</TT> needs to support deposit, withdraw, andaccount balance operations, in addition to authenticating the customer through theATM card. <TT>ATMCard</TT>, in turn, needs to indicate the accounts that it is authorizedto use, ought to support the capability to add and remove accounts to and from itslist of authorized accounts, and--for the purposes of this application, anyway--mustinclude the PIN associated with that <TT>ATMCard</TT> as a member data item.</P><P>The interface for the <TT>ATM</TT> class looks like this:</P><PRE><FONT COLOR="#0066FF"><TT>name : string</TT><TT>withdraw(card : ATMCard, account : Account, pin : integer,</TT><TT>        amount : float) : float</TT><TT>deposit(card : ATMCard, account : Account, pin : integer,</TT><TT>        amount : float) : float</TT><TT>getBalance(card : ATMCard, account : Account, pin : integer)</TT><TT>        : float</TT></FONT></PRE><P>Note that each of the operations in the <TT>ATM</TT> class requires an <TT>ATMCard</TT>to identify the customer and the <TT>Account</TT>s for which he or she is authorizedaccess, an <TT>Account</TT> on which to operate, and a <TT>pin</TT> (which for thepurposes of this application is simply an integer) to authenticate the customer.</P><P><TT>ATMCard</TT>'s interface resembles the following:</P><PRE><FONT COLOR="#0066FF"><TT>pin : integer</TT><TT>getAccounts() : Account[]</TT><TT>addAccount(account : Account) : void</TT><TT>removeAccount(account : Account) : void</TT><TT>isAuthorized(account : Account) : boolean</TT></FONT></PRE><H3><A NAME="Heading4"></A><FONT COLOR="#000077">Modifying Existing Classes</FONT></H3><P>Of course, you can't just create the <TT>ATM</TT> and <TT>ATMCard</TT> classesand expect the <TT>ATM</TT> capability to be integrated with the rest of the application;you must also modify some of the existing classes. For example, an <TT>ATMCard</TT>has to come from somewhere; typically, it is issued by a <TT>Bank</TT>. Also, a <TT>Customer</TT>would have some knowledge of the <TT>ATMCard</TT> because the <TT>ATMCard</TT> isintended to be used by <TT>Customer</TT>s in the first place. Finally, a <TT>Customer</TT>should be able to locate and access <TT>ATM</TT>s, so it would be reasonable to modify<TT>BankServer</TT> to provide locations of <TT>ATM</TT>s as well as <TT>Bank</TT>s.</P><P>First, consider the <TT>Bank</TT> class, which must be able to issue <TT>ATMCard</TT>sto <TT>Customer</TT>s. A reasonable way to achieve this functionality is to add thefollowing method to <TT>Bank</TT>:</P><PRE><FONT COLOR="#0066FF"><TT>issueATMCard(pin : integer, account : Account) : ATMCard</TT></FONT></PRE><P>Here, it is assumed that when the <TT>ATMCard</TT> is issued, an initial <TT>pin</TT>will be set; that <TT>ATMCard</TT> will also be authorized initially to access thegiven <TT>Account</TT>. Note that for this application, it is the responsibilityof the caller (presumably a <TT>Customer</TT>) to retain the <TT>ATMCard</TT> afterit is created.</P><P><TT>Customer</TT>, again, should be modified to become aware of <TT>ATMCard</TT>sso that a <TT>Customer</TT> can make use of them. It turns out that the only additionrequired to <TT>Customer</TT> is an internal list of the <TT>ATMCard</TT>s held bythat <TT>Customer</TT>; for the sake of convenience, you might add a method thatenables other objects to access that list of <TT>ATMCard</TT>s. However, for thepurposes of this application, you can assume that other objects don't need accessto this information (besides, people don't usually share information about theirATM cards with other people!). For your purposes, no changes are required to the<TT>Customer</TT> interface itself (changes to the <TT>Customer</TT> implementationcome later).</P><P>Finally, <TT>BankServer</TT> should be modified to facilitate access to <TT>ATM</TT>sas well as <TT>Bank</TT>s. Recall the operations provided in the BankServer interfacethat enable access to <TT>Bank</TT>s:</P><PRE><FONT COLOR="#0066FF"><TT>registerBank(bank : Bank) : void</TT><TT>unregisterBank(bank : Bank) : void</TT><TT>getBanks() : Bank[]</TT></FONT></PRE><P>It seems reasonable to mimic this interface for <TT>ATM</TT>s, yielding the followingoperations:</P><PRE><FONT COLOR="#0066FF"><TT>registerATM(atm : ATM) : void</TT><TT>unregisterATM(atm : ATM) : void</TT><TT>getATMs() : ATM[]</TT></FONT></PRE><P>The modified class diagram--expanded to include the new <TT>ATM</TT> and <TT>ATMCard</TT>classes, along with the modified <TT>Bank</TT> class--appears in Figure 8.1. <BR><BR><A HREF="javascript:popUp('01.jpg')"><B>Figure 8.1.</B></A> <I>The modified </I><TT>Bank</TT><I>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -