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

📄 apa.htm

📁 corba比较入门级的介绍详细间接了corba访问发布各种细节。
💻 HTM
📖 第 1 页 / 共 4 页
字号:
	<TT>} else {</TT><BR>	<TT>// Symbol was not found.</TT><BR>	<TT>throw new InvalidStockSymbolException();</TT><BR>	<TT>}</TT></FONT>	<P><FONT COLOR="#0066FF"><BR>	<TT>}</TT></FONT></P>	<P>The changes to the client are limited to the <TT>doSomething()</TT> method, which	now catches the exception and prints a warning message:<BR>	<FONT COLOR="#0066FF"><BR>	<TT>// Do some cool things with the StockServer.</TT><BR>	<TT>protected void doSomething() {</TT><BR>	<TT>try {</TT><BR>	<TT>// Get the valid stock symbols from the StockServer.</TT><BR>	<TT>String[] stockSymbols = myStockServer.getStockSymbols();</TT><BR>	<TT>// Display the stock symbols and their values.</TT><BR>	<TT>for (int i = 0; i &lt; stockSymbols.length; i++) {</TT><BR>	<TT>try {</TT><BR>	<TT>System.out.println(stockSymbols[i] + &quot; &quot; +</TT><BR>	<TT>myStockServer.getStockValue(stockSymbols</TT><BR>	<TT>[i]));</TT><BR>	<TT>} catch (InvalidStockSymbolException ex) {</TT><BR>	<TT>System.out.println(&quot;Invalid stock symbol.&quot;);</TT><BR>	<TT>}</TT><BR>	<TT>}</TT><BR>	<TT>} catch (org.omg.CORBA.SystemException ex) {</TT><BR>	<TT>System.err.println(&quot;Fatal error: &quot; + ex);</TT><BR>	<TT>}</TT><BR>	<TT>}</TT></FONT></DL><PRE></PRE><H2><A NAME="Heading11"></A><FONT COLOR="#000077">Day 5: Designing the System: ACrash Course in Object-Oriented Analysis and Design</FONT></H2><H3><A NAME="Heading12"></A><FONT COLOR="#000077">Quiz</FONT></H3><DL>	<DD><B>1</B>. Identify the potential objects in the system described here: An ordering	system allows customers to order products from a particular company. Each order consists	of one or more line items, each of which identifies a quantity and a particular product.	Each product, in turn, has an associated price.</DL><P>Possible objects in this system can be identified by picking out the nouns: <I>order,line item, quantity, product, and price. (Further analysis might reveal that someof these--particularly quantity and price--do not work well as objects, but thatdepends on the application.)</I><DL>	<DD><B>2. What is UML, and what is it good for?<BR>	</B>The UML, or Unified Modeling Language, is used to facilitate the object-oriented	analysis and design process. UML can be used to model a number of aspects of the	system, from static design (such as class diagrams) to dynamic (such as use cases	and scenarios).<BR>	<B><BR>	3</B>. For an order-processing system design, one requirement given is &quot;must	be fast.&quot; Is this a reasonable expression of this requirement, or could it be	improved? If so, how?</DL><P>Because <I>fast by itself is not an easily quantifiable term and thus cannot betested readily, &quot;must be fast&quot; is probably not a reasonably expressed requirement.A more quantifiable requirement would be to require an average system response timeof, for example, one second or less.</I><H3><A NAME="Heading13"></A><FONT COLOR="#000077">Exercise</FONT></H3><P>Modify the system design so that a <TT>Bank</TT> consists of <TT>Branch</TT>es,each of which owns some of the <TT>Customer</TT> <TT>Account</TT>s. Draw the classdiagram for the modified design.</P><P>Your modified class diagram should resemble the one shown in Figure A.1. Notethat the <TT>Account</TT> creation responsibility has been moved from the <TT>Bank</TT>to the <TT>Branch</TT>, although the <TT>Bank</TT> and its constituent <TT>Branch</TT>esshare the capability to enumerate and close <TT>Account</TT>s. <BR><BR><A HREF="javascript:popUp('01.jpg')"><B>Figure A.1</B></A> <I>The modified </I><TT>Bank</TT><I>application class diagram.</I><H2><A NAME="Heading14"></A><FONT COLOR="#000077">Day 6: Implementing Basic ApplicationCapabilities</FONT></H2><H3><A NAME="Heading15"></A><FONT COLOR="#000077">Quiz</FONT></H3><DL>	<DD><B>1</B>. It was noted earlier that <TT>_is_equivalent()</TT> is not guaranteed	to return <TT>TRUE</TT> when two object references refer to the same object. Can	you think of a mechanism that would more reliably determine whether two references	refer to the same object? (For simplicity, assume the objects are of the same type.)<BR>	A mechanism could assign global unique identifiers (GUIDs) or universal unique identifiers	(UUIDs) to objects and make the identifiers available to client applications (through	an accessor method such as <TT>getGUID()</TT>). Such a mechanism could more reliably	determine object identity by comparing identifiers; two objects that return the same	GUID must be the same object.<BR>	<B><BR>	2</B>. What would happen if <TT>_release()</TT> were not called on an object that	had earlier been <TT>_duplicate()</TT>d?<BR>	If <TT>_release()</TT> were not called on an object, the object would live forever;	its reference count (in a reference counting implementation) would never reach zero.<BR>	<B><BR>	3</B>. Why does <TT>NewCustomerMain.cpp</TT> have a <TT>try ... catch (const CORBA::Exception&amp;	ex)</TT> block?<BR>	The <TT>CORBA::Exception</TT> is a generic exception that can be thrown by any remote	method. Because a number of remote methods are called in <TT>NewCustomerMain.cpp</TT>,	they are done so inside this <TT>try ... catch</TT> block.</DL><H3><A NAME="Heading16"></A><FONT COLOR="#000077">Exercise</FONT></H3><P>Modify the client application so that it prints the names of the <TT>Customer</TT>swho are associated with the <TT>Account</TT> that was created. (The single <TT>Customer</TT>printed should be the same <TT>Customer</TT> whose information was entered on thecommand line.)</P><P>After line 85 of <TT>NewCustomerMain.cpp</TT> (refer to Listing 6.21), add thefollowing code. This code gets the <TT>Account</TT> owners using the <TT>getCustomers()</TT>method, then iterates through the sequence of <TT>Customers</TT> returned by thatmethod, printing the name of each <TT>Customer</TT> (as returned by <TT>name()</TT>).</P><PRE><FONT COLOR="#0066FF"><TT>// Print out list of Customers owning the Account.</TT><TT>cout &lt;&lt; &quot;  Printing list of Account owners:&quot; &lt;&lt; endl;</TT><TT>CustomerList* customers = account-&gt;getCustomers();</TT><TT>for (CORBA::ULong i = 0; i &lt; customers-&gt;length(); i++) {</TT><TT>    cout &lt;&lt; &quot;    Owner &quot; &lt;&lt; i + 1 &lt;&lt; &quot;: &quot; &lt;&lt; ((*customers)[i])-&gt;</TT><TT>            name();</TT><TT>}</TT></FONT></PRE><H2><A NAME="Heading17"></A><FONT COLOR="#000077">Day 7: Using Exceptions to PerformError Checking</FONT></H2><H3><A NAME="Heading18"></A><FONT COLOR="#000077">Quiz</FONT></H3><DL>	<DD><B>1</B>. What does it mean to raise (or throw) an exception?<BR>	To raise an exception means that a new exception is created and passed to the caller	of the method that raised the exception. The caller can then handle the exception	or pass it to its caller.<BR>	<B><BR>	2</B>. What does it mean to catch an exception?<BR>	To catch an exception means to handle an exception that was raised by a method that	was called. Catching an exception might involve displaying an error message to the	user, trying to resolve the condition that caused the exception to be raised, or	doing nothing at all.<BR>	<B><BR>	3</B>. Why are exceptions useful?<BR>	Exceptions are useful because they provide a structured form of error handling. For	example, without exceptions, a given method would have to reserve certain return	results to signify an error condition; a caller of such a method would have to check	for each of these special return codes. Exceptions greatly simplify the complexities	that can otherwise arise from error handling mechanisms.</DL><H3><A NAME="Heading19"></A><FONT COLOR="#000077">Exercises</FONT></H3><DL>	<DD><B>1</B>. Modify the following interface definition so that appropriate exceptions	are raised in appropriate places.<BR>	<FONT COLOR="#0066FF"><BR>	<TT>exception InvalidNumberException { };</TT><BR>	<TT>exception NoIncomingCallException { };</TT><BR>	<TT>exception NotOffHookException { };</TT><BR>	<TT>interface Telephone {</TT><BR>	<TT>void offHook();</TT><BR>	<TT>void onHook();</TT><BR>	<TT>void dialNumber(in string phoneNumber);</TT><BR>	<TT>void answerCall();</TT><BR>	<TT>};</TT></FONT>	<P>One potential solution is as follows:<BR>	<FONT COLOR="#0066FF"><TT>exception InvalidNumberException { };</TT><BR>	<TT>exception NoIncomingCallException { };</TT><BR>	<TT>exception NotOffHookException { };</TT><BR>	<TT>interface Telephone {</TT><BR>	<TT>void offHook();</TT><BR>	<TT>void onHook();</TT><BR>	<TT>void dialNumber(in string phoneNumber)</TT><BR>	<TT>raises (InvalidNumberException, NotOffHookException);</TT><BR>	<TT>void answerCall()</TT><BR>	<TT>raises (NoIncomingCallException);</TT><BR>	<TT>};</TT></FONT></DL><PRE></PRE><DL>	<DD>This solution assumes that it is not valid to dial a number unless the <TT>Telephone</TT>	is already off the hook. It might be equally reasonable for <TT>dialNumber()</TT>	to call <TT>offHook()</TT> if the <TT>Telephone</TT> is not already off the hook.<BR>	<B><BR>	2</B>. Implement the interface from exercise 1, raising the appropriate exceptions	under the appropriate conditions. (Most of the methods probably won't do anything,	except for <TT>dialNumber()</TT>, which will likely check the validity of the given	phone number).<BR>	The complete solution is not given here, but the implementation for the exercise	1 solution would look like this (the following is in pseudocode):<BR>	<FONT COLOR="#0066FF"><TT>void dialNumber(string phoneNumber) {</TT><BR>	<TT>if (<I>telephone is on hook</I>) {</TT><BR>	<TT>raise NotOffHookException;</TT><BR>	<TT>}</TT><BR>	<TT>if (<I>phone number is invalid</I>) {</TT><BR>	<TT>raise InvalidNumberException;</TT><BR>	<TT>}</TT><BR>	<I><TT>proceed to dial the number...</TT></I><BR>	<TT>}</TT><BR>	<TT>void answerCall() {</TT><BR>	<TT>if (<I>no incoming call is being placed</I>) {</TT><BR>	<TT>raise NoIncomingCallException;</TT><BR>	<TT>}</TT><BR>	<I><TT>proceed to answer the call...</TT></I><BR>	<TT>}</TT></FONT></DL><PRE></PRE><H2><A NAME="Heading20"></A><FONT COLOR="#000077">Day 8: Adding Automated TellerMachine (ATM) Capability</FONT></H2><H3><A NAME="Heading21"></A><FONT COLOR="#000077">Quiz</FONT></H3><P>What are the four steps you'll usually follow to make enhancements to a CORBAapplication?</P><P>The steps are to define additional requirements, modify the system design, modifythe IDL definitions to reflect the new design, and, finally, implement the new functionality.<H3><A NAME="Heading22"></A><FONT COLOR="#000077">Exercise</FONT></H3><P>Add an operation to the <TT>ATM</TT> interface that allows funds to be transferredbetween <TT>Account</TT>s. Be sure to provide appropriate exceptions as well.</P><P>The IDL should look something like this:</P><PRE><FONT COLOR="#0066FF"><TT>float transfer(in ATMCard card, in Account fromAccount, in Account</TT><TT>        toAccount, in short pin in float amount)</TT><TT>        raises (AuthorizationException, InvalidAmountException,</TT><TT>        InsufficientFundsException);</TT></FONT></PRE><P>Note that the implementation of this method will likely need to use the <TT>ATMCard</TT>to check the authorization for both the <TT>fromAccount</TT> and <TT>toAccount</TT>parameters. (Actually, it might be reasonable to allow transfers to any <TT>Account</TT>,but real ATM cards allow transfers only between accounts on which those cards areauthorized.)<H2><A NAME="Heading23"></A><FONT COLOR="#000077">Day 9: Using Callbacks to Add PushCapability</FONT></H2><H3><A NAME="Heading24"></A><FONT COLOR="#000077">Quiz</FONT></H3><DL>	<DD><B>1</B>. Why does the issue of thread safety become important in the sample	application developed in this chapter?<BR>	Thread safety is important because multiple threads might attempt to access the same	data simultaneously. To prevent the possible corruption of data, access to such data

⌨️ 快捷键说明

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