• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NX: Singleton in Ken's design.

 
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ken wrote (about his design):


The most important implementation of Services is the ServicesImpl class which is a singleton.
The ServicesImpl singleton is the only object that interacts with the Data singleton and hence the only direct user of the locking/unlocking API.
The Standalone application functionality gets its Services instance directly from ServicesImpl's static getServices method.


Now my question to Ken, or anybody is:
Are the methods of the ServicesImpl singleton synchronized? Because, if they are not, I see no need for a singleton here. At least not in my design.
My data class is already thread safe, synchronized on the raf and the lock map. My version of the ServicesImpl class , DBClientImpl, just provide server side booking (lock, book, unlock), and find methods.
My RemoteDBClientImpl class delegates everything to DBClientImpl. But I don't see why DBClientImpl has to be a singleton. Surely each instance of my RemoteDBClientImpl can have it's own instance of DBClientImpl.
What am I missing? Or is my design different?
 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jacques,
My ServicesImpl class really does NOT need to be a singleton. It is completely threadsafe, not because it has no synchronization, but because it has no state of its own.
Originally, ServicesImpl was a nested class within Data. I did this as a convenience to give it direct access to Data's private parts. Eventually, this was no longer necessary. The last bit of refactoring I did before submission was to pull ServicesImpl out into a separate class to make it easier to understand for the junior programmer. If I had given it a little more thought, I would have realized that I did not need it to be a singleton and my design would have been better for it.
 
Jacques Bosch
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ken.
Thanx for clearing that up for me.
That's what I was thinking, but I was wondering whether I was missing something.
See ya.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
I just wanted to clarify something with regards to Ken's implementation of a business layer. I am confused about the relationship between the ServiceImpl and RemoteServiceImpl classes. Why have two classes that implement the Services interface?
Thanks,
Jonathan
 
Ken Krebs
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jonathan,
ServicesImpl provides the real functionality. RemoteServicesImpl acts as an RMI wrapper for it, that is, it has a reference to a ServicesImpl and its implementation of Services (extended by RemoteServices) delegates all work to it. RemoteServicesImpl also provides static factory methods for getting the RMI server and the stub.
The network code has to be completely bypassed in standalone mode so in that case SevicesImpl is used directly. The gui client has no idea which one it's using. All it knows is that it implements the Services interface.
Does that clarify it for you ?
 
Jonathan Pengelly
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ken. I understand now.
 
I need a new interior decorator. This tiny ad just painted every room in my house purple.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic