xhtml
 

Combining Classes

Where would the book shop program go from here? One direction is to suppose that the shop diversifies or that you want to prepare for the day when it does. Then, there might be lots of different kinds of products, each with its own class. They would all have prices, and you might have a lot of repeated awkward code which handles amounts of money as integers. This is an implementation detail which should be handled in one place, not spread all over the program, so you might design a Money class to handle it, and change Book to use it, maybe like this:

Money.java
Book.java

Another direction the development might go in is to develop a class to represent a stock of books, perhaps with facilities for searching for a particular book by part of its title. We won't try and do that here, because it becomes much easier when we an use library classes.


Back