Developing Use Cases


After the wireframes are complete, the customer and the development team usually sits down to work up the use cases. The use cases represent a drilling down into the particulars of the requirements. Normally, use cases start with the initial state at which the application is encountered by a visitor, and then proceed to follow every possible path that could be taken, asking what could go wrong (error conditions) and what actions must be taken.

This exercise is especially critical with Struts because the list of possible jumping points from a given page represents the possible targets of the action bean. But, as with everything, it's not required to get absolutely everything right on the first pass.

Use Case: Initial Page

When a visitor requests the index page of the site, she is presented with the main site page. The market quotes are contained in a separate file, which is updated by a cron job. The technology stock quotes are looked up in real-time during the page creation. The news stories on the right are created manually by the staff and exist in separate files.

The possible transitions from this page are

  • By filling in a username and password, which brings the user back to the same page, but as a logged-in user

  • By clicking on the create account link, which brings the user to the Create Account page

The possible error conditions on this page are

  • The username or password is incorrect, in which case an error message will be displayed above the login form.

Use Case: Account Creation Page

From the account creation page, the visitor can establish a new account. The possible transitions from this page are

  • By filling in a username and password, which brings the user to the main page, but as a logged-in user

  • By filling in the create account form, which causes the account to be created in the database, and logs in the visitor as the newly created user, returning her to the main page

The possible error conditions on this page are

  • The username or password is incorrect, in which case an error message will be displayed above the login form.

  • Any of the mandatory fields is blank (only street address 2 and work extension are optional). Missing fields are flagged with an error message.

  • The username is already in use. This causes an error message to be printed above the form.

  • The e-mail address does not contain an @ , which is flagged as an error on the field.

  • The state is not a proper two-letter state abbreviation, which is flagged as an error on the field.

  • The postal code is not a five- or nine-digit number, possibly with a dash, which is flagged as an error on the field.

  • The home or work phones are not 10-digit numbers , possibly with parentheses, dashes, or spaces, which is flagged as an error on the field.

  • An error occurs during the database write operation, which causes the visitor to be sent to a general error page.

Use Case: Logged-In User on Main Page

After the user has logged in, either by creating a new account or by using the login form successfully, the main page replaces the login form with the mini-view of the portfolio. If there are no stocks in the portfolio, the visitor is given a link to the add transaction page. If there are stocks in the portfolio, a mini-view is presented with the same link underneath the view.

The possible transitions from this page are

  • By clicking the add transaction link, which takes the visitor to the add transaction page

Use Case: Add Transaction Page

At the add transaction page, the visitor is offered a form with which to add a stock transaction to her portfolio. Beneath that, a full display of their current portfolio is shown, listing the following items:

  • Symbol ” The stock symbol of the company.

  • Company Name ” The full name of the company.

  • Holdings ” Number of shares held in aggregate the total of all stock purchases minus all stock sales).

  • Latest Quote ” Last quote for that stock.

  • Average Cost ” Computed as follows : Iterate over the stock purchases and sales. For each purchase, use the following formula where AC is the current average cost, initialized at 0; NS is the number of shares, which also starts at 0; SC is the per share price of the new shares; and SI is the number of shares being added:

    ((AC * NS) + (SC * SI)) / (NS + SI) = AC

    NS + SI = NS

    For stock sales, AC is not changed, but NS is decremented by the shares sold.

    For example, in the case in which 500 shares of IBM are bought at 10, 250 are sold, and then another 250 are bought at 20, the calculation would be

    ((0 * 0) + (10 * 500)) / (0 + 500) = 10

    0 + 500 = 500

    500 - 250 = 250

    ((10 * 250) + (20 * 250)) / (250 + 250) = 15

    250 + 250 = 500

  • Change From Close ” Per-share price change since the last market close, or the word CLOSE if the market is currently closed.

  • Change From Purchase ” Per share price change since the stock was purchased.

  • Current Value ” Current holdings times current quote.

  • Profit or Loss ” Change from Purchase times holdings.

As you can see from this, it is important to gather crucial details of business logic as early as possible. Asking a question such as, "How do you compute the average cost of a share?" can save a developer from going up the wrong path later.

The possible transitions from this page are

  • By filling in a stock transaction, which brings the visitor back to the main page after adding the stock transaction

  • By clicking on the return to main page link, which brings the user back to the main page with no change in the portfolio

  • By clicking on the update portfolio link on the mini-view, which brings the user back to this page

The possible error conditions on this page are

  • Any of the fields is blank. Missing fields are flagged with an error message.

  • The stock symbol is not found in the database, which is flagged as an error on the field.

  • The date is not in a valid date format or is after today's date, which is flagged as an error on the field.

  • The price or quantity is not a number, which is flagged as an error on the field.

  • A database error occurs while saving the transaction, which causes the visitor to be taken to the general errors page.



Struts Kick Start
Struts Kick Start
ISBN: 0672324725
EAN: 2147483647
Year: 2002
Pages: 177

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net