• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[The Book vs URLyBird 1.1.2] SCJD Exam with j2se - Factory pattern vs Facade pattern

 
Jerry Goldbaum
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is my first post here so, Hello everyone!

In The Book "SCJD Exam with j2se" (by Andrew Monkhouse ), in RMI section, factory pattern is utilized to obtain new instance of DVDDatabase class.
I was analyzing this idea and I have got a question that I am not able to answer myself:
Why do we need to multiple instances of this class? Can't it be done with only single instance? Every client would be supplied with the same reference of DVDDatabase (singleton?) and requests would be processed by "file access" class object according to locking mechanism implemented in "file access" class?

I remember that in book example client ID is provided by reference to DVDDatabase, and in my case client ID is provided as a number requested when locking/unlocking methods (so called: cookie).

So in my opinion when i have got a cookie value I do not need to utilize a factory pattern?

Best regards,

[ October 31, 2008: Message edited by: tnts2008 ]

[ October 31, 2008: Message edited by: tnts2008 ]

[ November 03, 2008: Message edited by: tnts2008 ]

[ November 03, 2008: Message edited by: tnts2008 ]
[ November 03, 2008: Message edited by: tnts2008 ]
 
mohamed sulibi
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi;

yes i am with you; my interface provided use cookie so i don't generate unique instances of the data class also i register only one instance in the rmi stub.

regards.
Mohamed Sulibi
 
christian combarel
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, Jerry
In the RMI solution, each client receive a different instance of the DVDDatabase class.
This is a mean to identify the client on the server side for reserve/release operations, as a thread is not linked to a client.
In the "ReservationsManager" class, a Map maps UPCs with DvdDatabase instances.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic