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

NX: The Lock and Unlock Abstraction

 
Javini Javono
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic