Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Monkhouse book: Logical reserve methods

 
Simon Cockayne
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have been reading the book "SCJD Exam with J2SE 5" (2nd edition Andrew Monkhouse and Terry Camerlengo).

First question - is there a commonly accepted abbreviation for 'that' book on this forum?

Second question:

Page 154 discusses "Creating our logical Reserve methods".

I am slightly confused as to why the map 'reservations' contains 'UPC' and 'owner'.

For example the 'releaseDVD' method checks to see if the renter trying to unlock matches the renter in the map.

But does this logically support the fact there might be say TWO copies of a single DVD title "Finding Nemo", with UPC 123456, that two different renters want to hire?

No doubt I am missing something obvious.

Any clarification would be warmly welcomed.

Thanks,

Simon.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't stare blindly at the design decisions the book makes at that level, they're based on the (fictional) assignment used as the basis for the book examples, not on any real assignment.

If the map contains UPC and owner, what makes you think the software checks UPC and title?
 
Simon Cockayne
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeroen,

Thanks for the reply.

I think I understand your point that the design decisions made in the book, for a fictional assignemnt, might not be relevant to my assignemnt and they may not be the best choices.

However, when I read something I do not understand, it irks me.

My question stands...is the design wrong...or am I missing something.

I am not sure what you mean about "What makes you think...". Can you reword it.

I really appreciate your time and trouble.


Regards,

Simon.
 
Liviu Carausu
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Simon,

Looking at the code, it seems like the implementation considers that is only

one DVD available for one UPC. It looks like I also miss something....
 
Simon Cockayne
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I had a revelation on the train!

I, suddenly, realised that the reserveDVD and releaseDVD are merely used to obtain (reserve) and release a lock on the UPC 'RECORD'.

AFTER, the lock has been obtained (signalling a client has locked the UPC record ), the number of copies of the DVD (UPC) can be amended, e.g. increased or decreased and then the lock can be released.

If you read the section on testing towards the end of the book this makes it clear.

I must say though the names of the "locking" methods, reserveDVD and releaseDVD clash with the business procedures, of reserving and releasing (returning) a DVD in a terrible manner.

Had better method names been chosen, it would have caused me less heartache.

How about lockUPCRecord unlockUPCRecord?


I also see that the name of the acutal renters are not stored, rather it is just a tally of copies available for rent.

Thanks,

Simon.
[ May 26, 2006: Message edited by: Simon Cockayne ]
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

Sorry, I am off for a short holiday, and wont have access to all my notes until next week. But when I get back I will look into this.

Off the top of my head though, though, I think that the logic is still sound. Although there may be multiple copies of any given DVD, we do not want multiple people adding and subtracting to the number currently available. So only one person can lock an individual record.

So in the example of 2 copies of "Finding Nemo" (far too few for such a great movie), we would have:
  • User A locks the record for that DVD
  • User A confirms that there is at least one copy remaining.
  • User A rents the movie (decrementing the count of number of movies available)
  • User A releases the lock on that DVD
  • User B locks the record for that DVD
  • User B confirms that there is at least one copy remaining.
  • User B rents the movie (decrementing the count of number of movies available)
  • User B releases the lock on that DVD

  • Regards, Andrew
     
    Jeroen T Wenting
    Ranch Hand
    Posts: 1847
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    yes, and all those copies will have different UPCs. The lock is obtained on the UPC only, not the title.

    If there were 2 copies of the same UPC and you locked on the UPC you'd be unable to lock both at the same time as the locking mechanism wouldn't know which one was locked.
     
    Simon Cockayne
    Ranch Hand
    Posts: 214
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hey Jeroen,

    You say "...yes, and all those copies will have different UPCs.".

    I understand that you are saying that if there are two copies of "Finding Nemo" (same film) that they would be represented by DIFFERENT UPCs.

    However, I understood from the book that each copy would have the SAME, common, UPC number.

    Please can you clarify?

    Regards,

    Simon.
     
    Jeroen T Wenting
    Ranch Hand
    Posts: 1847
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    if that's the case the UPC isn't a unique identifier for a record and can't be used to identify an individual record.
     
    Simon Cockayne
    Ranch Hand
    Posts: 214
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi...

    Exactly! Which is why I could not work out why UPC (alone) was being used as a lock in the "reserveDVD" method...which I thought was the method name to reserve a specific copy of a film.

    But...as I said, "reserveDVD" method does NOT (in of itself) reserve a copy of a DVD. Hence my qualm with the method name...a better name would have been "lockUPCRecord".

    Cheers,

    Simon.
     
    Robert McDonald
    Greenhorn
    Posts: 17
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Simon,

    I agree with you - the naming of these methods caused me a bit of confusion initially as i also thought they were business methods. However, I think Andrew clarifies the function in an previous posting i.e. that these are used for the locking mechanism.

    The book says that the upc is a unique product code so i guess multiple copies of the Finding Nemo DVD would have the same UPC. The DVD class outlined in p122 indicates that a DVD instance includes an attribute 'copies' i.e. the number of copies of the DVD. So this means that each copy of the DVD is 'not' a separate record and all copies are locked together so that concurrent decrementing/incrementing is avoided.

    I hope i'm understanding this correctly!!
     
    Jeroen T Wenting
    Ranch Hand
    Posts: 1847
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    depends on what you mean by "unique product code".
    Is it a unique code given to the product by the manufacturer (in which case you're right) or by the rental agency (in which case each individual DVD might be considered a distinct product)?

    It's ambiguous, just like the real assignment. You'll have to make a decision about that based on the actual data.
     
    Simon Cockayne
    Ranch Hand
    Posts: 214
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Robert,

    I think you are understanding correctly.

    Jeroen, I understand that UPC is for a product, rather than an instance of a product.

    I have no doubt that Andrew can clarify all, upon his return.

    Cheers,

    Simon.
     
    Jeroen T Wenting
    Ranch Hand
    Posts: 1847
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    ah, but what's a product. That's what I am trying to make you think about.
    For the record company it's a release, so there can be many DVDs of the same title all with the same product number.
    For the rental agency it would be the individual DVD that's a product (or even the contract renting out a specific disk) and each DVD would have a serial number (probably in practice the number used by the record company appended with a serial number).
     
    Robert McDonald
    Greenhorn
    Posts: 17
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Jeroen,

    I'm not sure that it is ambiguous. There's a note which describes it as 'an official designation for a product' and a 'unique number identifying that product worldwide'. (Although later there is also a note which says that it only applies to US and Canada). Whatever description is correct, it appears to be a unique code which identifies a product and not an instance of a product. In this context, I think the rest of the locking code makes sense.
     
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander
    Pie
    Posts: 12014
    220
    C++ Firefox Browser IntelliJ IDE Java Mac Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi everyone,
    I have been reading the book "SCJD Exam with J2SE 5" (2nd edition Andrew Monkhouse and Terry Camerlengo).

    First question - is there a commonly accepted abbreviation for 'that' book on this forum?
    The previous edition used to be known as "Max's book", so I suppose "Andrew's book" would work (although not being technically correct).
    I think I understand your point that the design decisions made in the book, for a fictional assignemnt, might not be relevant to my assignemnt and they may not be the best choices.
    As mentioned in the book, we constantly had to think about how we could present information to you, the reader, that would help you with your assignment without actually giving away the real solution. One of the areas that was hardest for us was how close we could get to the real design decisions and real methods of the Data class. Where possible, we noted where we were deliberately deviating from what might be considered desirable in the real assignment.

    As for the question that prompted that quote: I see that you later correctly noted that the reservations object in the ReservationsManager class is only used for locking and unlocking the record - it is not used to track who has rented the DVD.

    I apologize for the confusion with the naming convention - it was something we discussed, and we decided that calling our methods 'lock' and 'unlock' might be too strong a giveaway .
    The book says that the upc is a unique product code so i guess multiple copies of the Finding Nemo DVD would have the same UPC. The DVD class outlined in p122 indicates that a DVD instance includes an attribute 'copies' i.e. the number of copies of the DVD. So this means that each copy of the DVD is 'not' a separate record and all copies are locked together so that concurrent decrementing/incrementing is avoided.
    Correct. The UPC identifies the DVD from a manufacturer's standpoint: that is, each copy of "Finding Nemo" will have the same UPC. In real life we would probably want some way to identify who rented the DVD, but that would have been taking us either beyond the scope of our sample assignment (requiring an aditional 'database table'), or back into the problem of getting too close to the real assignment if we had some way to identify the renter for each individual DVD.

    Regards, Andrew
     
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander
    Pie
    Posts: 12014
    220
    C++ Firefox Browser IntelliJ IDE Java Mac Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Jeroen,

    Could you please take a look at my latest private message to you?

    Thanks and regards, Andrew
     
    Simon Cockayne
    Ranch Hand
    Posts: 214
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Andrew,

    Thanks for taking the time to explain.

    I do like "Andrew's book".

    Cheers,

    Simon.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic