aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX:  The Lock and Unlock Abstraction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX:  The Lock and Unlock Abstraction" Watch "NX:  The Lock and Unlock Abstraction" New topic
Author

NX: The Lock and Unlock Abstraction

Javini Javono
Ranch Hand

Joined: Dec 03, 2003
Posts: 286
Hi,
From "direct" conceptual code like this:.

to code like this:

is a form of abstraction.
What Sun appears to be imposing, among other things
is an abstraction; that is, instead of placing your business
calls within a wait()/notifyAll() construct, you simply call
lock() and unlock() instead.
Question: If you had your choice, and you were really writing
this software for a real company, and you really did have
unlimited time (a fantasy, but the assumption in this
question), would you implement lock() and unlock() which
appear to be abstractions? And if so or not, why?
Thanks,
Javini Javono
[ January 14, 2004: Message edited by: Javini Javono ]
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Question: If you had your choice, and you were really writing
this software for a real company, and you really did have
unlimited time (a fantasy, but the assumption in this
question), would you implement lock() and unlock() which
appear to be abstractions? And if so or not, why?

Not only would I abstract the lock/unlock logic, I would also remove the lock/unlock methods from the Data class. The guideline for class design is cohesion and low coupling that fascilitates code reuse, readability, and mainainance. To follow the guideline, you would design a class that has a well defined set of responsibilities and has as few dependencies as possible.
In the case of locking/unlocking, this functionality clearly has very little to do with what Data class is all about (retrieving and modifying data), and is best encapsulated in its own class. The benefits would be obvious, -- you would be able to change the locking/unlocking without affecting the data access, and vise versa.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: The Lock and Unlock Abstraction