[Tutor] How to refactor a simple, straightforward script into a "proper" program?

Alan Gauld alan.gauld at yahoo.co.uk
Tue Jan 7 05:37:36 EST 2020


On 07/01/2020 04:31, David L Neil via Tutor wrote:

>> My only question is whether the dates are relevant to the book? Or do
>> you need a Reader object? It is the reader who has reading goals. The
>> book will tell you how much to read and current position. But it is not
>> interested in dates.
> 
> Not necessarily. The reader doesn't know if (s)he is about to drop dead!
> 
> Alternately, if the book has been borrowed (eg library), then it has a 
> finite availability.

That's true and raises a moot point. If building a library app its
possible to have a LendableItem class from which all loanable objects
derive, Or you can create a Loanable mixin that is added to all loanable
stock. But it is also possible to have a Loan class associated with a
StockItem... All 3 approaches work.

My preference is for a separate Loan since it avoids having twin
versions of every kind of library item - loanable and reference...
A Loan captures the transitive relationship between a borrower and
a StockItem. It is responsible for monitoring duration, issuing
notifications, raising fines etc.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list