Goal:
Type Abstraction.
Consider the following market class.
class Market { private Set<Item> wanted; // items for which prices are of interest private Bag<Item, Money> offers; // offers to sell items at specific prices // Note: Bag isn't a Java data type. Here, the bag entries are pairs. public void offer (Item item, Money price) // Requires: item is an element of wanted // Effects: add (item, price) to offers public Money buy(Item item) // Requires: item is an element of the domain of offers // Effects: choose and remove some (arbitrary) pair (item, price) from // offers and return the chosen price }
class Low_Bid_Market extends Market { public void offer (Item item, Money price) // Requires: item is an element of wanted // Effects: if (item, price) is not cheaper than any existing pair // (item, existing_price) in offers do nothing // else add (item, price) to offers
Low_Bid_Market
a valid subtype of Market
?
Appeal to the methods rule to back up your answer.
buy()
method always chooses the lowest price on an item.
class Low_Offer_Market extends Market { public Money buy(Item item) // Requires: item is an element the domain of offers // Effects: choose and remove pair (item, price) with the // lowest price from offers and return the chosen price
Low_Offer_Market
a valid subtype of Market
?
Appeal to the methods rule to back up your answer.