Ch09.ppt

422 views

Published on

Published in: Business, Economy & Finance
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
422
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • This project emphasizes team development and code reuse — precisely the aspects of software development that OOP is good for.
  • Brokerage firms encourage trading because they make money on commissions.
  • As in any business, stock trading has its own technical jargon.
  • This looks a lot like Instant Messenger , and in fact this part of SafeTrade is similar and can reuse Instant Messenger ’s code, with minor changes.
  • People often begin with the OO design, then do the detailed design. The structural design becomes a part of the detailed design. We begin with structures because one of our goals is to review them.
  • This project has been selected because many different data structures fit in naturally.
  • This part can be handled by one programmer or by Group 1, a part of the team. These classes can be tested independently from the rest of the project.
  • Unfortunately, these Java Messenger classes were not implemented as application-independent. We need to change them slightly, adding a Login interface, to make this subsystem suitable for this project and other similar projects. We can call it “login framework.” A framework is a reusable system of classes.
  • These classes would be written by Group 2.
  • This is the big picture. In a good design, classes are arranged in layers; more application-specific classes are in the top layers and simpler, general-purpose classes in the bottom layers. A good design decreases coupling (interdependencies between classes).
  • TradeOrder carries information between other objects of different types. An object like this is often immutable. Here an order can change if a part of it is executed. We could make it immutable and create a new order for the remaining shares.
  • This class implements all the logic for trading. That’s where the trading rules and algorithms are. Potentially we could split it into stock description and the trading strategy; we would then use the Strategy design pattern (Chapter 10).
  • Ideally, javadoc comments are written before code. Then javadoc documentation becomes part of the specifications, and programmers have convenient access to it. This table shows documentation similar to the javadoc view.
  • Name a few data structures used in SafeTrade. TreeSet , TreeMap , ListQueue , HashMap . What is a limit order and a market order? A limit order is an order to sell or buy shares at a given price or better; a market order is an order to sell or buy shares at the current market price. Why is HashMap a good choice to represent listed stocks? There are not too many of them, and we need instantaneous access to stocks for quotes and executing orders. Name a few SafeTrade classes. Stock , TradeOrder , Trader , Exchange . If you had to split the SafeTrade development team into two groups, which classes would you assign to each group? Group 1: SafeTrade , GUILogin , Login interface, Exchange ; Group2: Trader , TraderWindow , Stock , PriceComparator , TradeOrder
  • What Java Messenger class is converted into the Exchange class? Server . Explain the role of the Login interface in the SafeTrade project. It makes the login logic independent of any particular type of server. What data structures are used to hold buy and sell orders for a given stock? Why? Priority queues: one for sell orders and an inverted one for buy orders, based on price comparison. What is the role of the PriceComparator class? It provides a comparison method for trade orders, based on their prices (or market vs. limit). What data structure would be appropriate for keeping track of stock holdings for each trader? A HashSet or simply a LinkedList.
  • Ch09.ppt

    1. 1. Java Methods AB Data Structures Maria Litvin Gary Litvin Copyright © 2003-2004 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved . TM Data Structures in Action: A Case Study
    2. 2. Objectives: <ul><li>Get experience with a larger and more realistic software project, which models a toy stock exchange </li></ul><ul><li>Review the data structures studied in this course </li></ul><ul><li>Discuss issues involved in object-oriented design </li></ul><ul><li>Practice working on a software project as a team </li></ul>
    3. 3. SafeTrade Application <ul><li>Implements a toy Stock Exchange </li></ul><ul><li>Runs on a single computer </li></ul><ul><li>Can be structured as a team development project </li></ul><ul><li>Uses TreeSet , TreeMap , HashMap , ListQueue , and HeapPriorityQueue classes </li></ul><ul><li>Reuses some of the code from the Java Messenger project (Section 5.8) </li></ul>
    4. 4. Stock Market Basics <ul><li>Stocks are listed on a stock exchange, such as NYSE (New York Stock Exchange) </li></ul><ul><li>A particular stock is identified by its trading symbol (e.g., SUNW for Sun Microsystems or MSFT for Microsoft ) </li></ul><ul><li>Stocks are usually traded in multiples of 100 </li></ul><ul><li>Stock prices are in dollars and cents (can include fractions of cents in the real world) </li></ul><ul><li>Online brokerage firms allow customers to trade stocks online from their computers </li></ul>
    5. 5. Stock Market Basics (cont’d) <ul><li>Buy order — an order to buy shares of stock </li></ul><ul><li>Sell order — an order to sell shares of stock </li></ul><ul><li>Limit order — specifies the maximum price for a buy or a minimum price for a sell </li></ul><ul><li>Market buy order — an order to buy shares at the current market price (the lowest “ask” price) </li></ul><ul><li>Market sell order — an order to sell shares at the current market price (the highest bid price) </li></ul>
    6. 6. SafeTrade Application (cont’d) <ul><li>Allows registered “users” to “trade” shares of stocks </li></ul><ul><li>Users must login first; the program can register a new user </li></ul><ul><li>Users place “buy” and “sell” orders and can get price quotes for stocks </li></ul><ul><li>SafeTrade runs on a single computer; each active user opens a separate trading window on the screen </li></ul><ul><li>SafeTrade does not keep track of cash or of the number of shares available on each account </li></ul>
    7. 7. SafeTrade Application (cont’d)
    8. 8. SafeTrade Application (cont’d) <ul><li>Stock prices are in dollars and cents </li></ul><ul><li>The “exchange” keeps track of all buy and sell orders for each stock </li></ul><ul><li>The “exchange” has a method to “list” (i.e., register) a new stock </li></ul><ul><li>An order is executed when the highest bid is not less than the lowest “ask” (i.e., the asking price) </li></ul><ul><li>In SafeTrade , all orders are partial orders: if only a portion of the order can be executed, then the largest possible number of shares is traded </li></ul>
    9. 9. SafeTrade Design Structural Design OO Design Detailed Design Data structures used Classes and objects Fields, constructors, and methods
    10. 10. SafeTrade Structural Design
    11. 11. Structural Design — Tradeoffs <ul><li>Registered traders: </li></ul><ul><li>large number (100,000s) </li></ul><ul><li>access time is not critical </li></ul>BST ( TreeMap ) <ul><li>Listed stocks: </li></ul><ul><li>relatively small number </li></ul><ul><li>fast access time is critical </li></ul>Hash table ( HashMap ) OK to sacrifice some wasted space for better performance
    12. 12. SafeTrade OO Design <ul><li>Part 1: Trader registration and login </li></ul><ul><ul><li>SafeTrade — small main class </li></ul></ul><ul><ul><li>GUILogin — reusable GUI for registration and login </li></ul></ul><ul><ul><li>Exchange — keeps track of the registered and logged-in traders </li></ul></ul><ul><ul><li>Trader — represents a trader </li></ul></ul><ul><li>The code for these classes is adapted from Java Messenger </li></ul>
    13. 13. SafeTrade OO Design (cont’d) Java Messenger SafeTrade
    14. 14. SafeTrade OO Design (cont’d) <ul><li>Part 2: Stocks and orders </li></ul><ul><ul><li>Stock — represents a stock </li></ul></ul><ul><ul><li>TradeOrder — represents an order to buy or sell stock </li></ul></ul><ul><ul><li>PriceComparator — implements a comparator for orders, based on the bid or ask price </li></ul></ul>
    15. 15. SafeTrade OO Design (cont’d)
    16. 16. SafeTrade Detailed Design <ul><li>Constructors, methods, fields for each class </li></ul><ul><li>User interface: GUI, printouts, help, etc. </li></ul><ul><li>GUI may be a good starting point </li></ul>A trader’s window getQuote method placeOrder method receiveMessage method Quit method
    17. 17. SafeTrade Detailed Design (cont’d) <ul><li>TradeOrder objects carry information between traders, Exchange, stock objects </li></ul>TradeOrder fields determine its accessor and modifier methods
    18. 18. SafeTrade Detailed Design (cont’d) <ul><li>A Stock object represents information about one stock </li></ul><ul><li>Provides quotes for the stock </li></ul><ul><li>Holds all pending orders for the stock </li></ul><ul><li>Executes as many orders as possible when a new order arrives </li></ul>
    19. 19. SafeTrade Detailed Design (cont’d)
    20. 20. Review: <ul><li>Name a few data structures used in SafeTrade . </li></ul><ul><li>What is a limit order and a market order? </li></ul><ul><li>Why is HashMap a good choice to represent listed stocks? </li></ul><ul><li>Name a few SafeTrade classes. </li></ul><ul><li>If you had to split the SafeTrade development team into two groups, which classes would you assign to each group? </li></ul>
    21. 21. Review (cont’d): <ul><li>What Java Messenger class is converted into the Exchange class? </li></ul><ul><li>Explain the role of the Login interface in the SafeTrade project. </li></ul><ul><li>What data structures are used to hold buy and sell orders for a given stock? Why? </li></ul><ul><li>What is the role of the PriceComparator class? </li></ul><ul><li>What data structure would be appropriate for keeping track of stock holdings for each trader? </li></ul>

    ×