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 Contractor "tweaking" sun interface methods - signature question

 
BillLeighton
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I must implement methods from the interface Sun provided, in a Data class. My question is, if I were to add "syncronized" to some of the Sun interface methods, as well as add an additional exception to some of them (along with the required ones to throw per the interface) would this be OK? I am under the impression that the keyword "syncronized" and the exceptions thrown are NOT part of a method's signature. So would this count as "implementing" the methods correctly? Or am I playing with fire here?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Synchronization is not part of the interface presented by a method; it's an implementation detail. So you can synchronize much or little as necessary, ; this has nothing to do with whether you've implemented the interface.
As for exceptions - that's a different story. Exceptions are not technically part of a method's signature, but they certainly are part of the public interface - especially if they're checked exceptions. In NX-Contractor, you're required to implement a particular interface without changing that interface. You can't throw any checked exception not alreaady declared in the method interface you're implementing. You can, however, throw a RuntimeException (or subclass). That's legal as far as the comipler is concerned, and as far as the "must" rules of your assignment. It may or may not be good programming practice - in my assignment I view it as a necessary evil, better than the allowed alternatives. Others here prefer to use only the declared exceptions, e.g. convert any other exception to a FileNotFoundException if possible. Either option is probably acceptable; both have potential problems; gotta decide for yourself what makes the most sense to you.
 
Davidd Smith
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, jim
But the instructor does not say that the DBaccess interface can not be updated, does it say?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My instructions say I "must implement the following interface" and then they tell me the interface (named DB, not DBAccess in my assignment). I don't change their interface at all. But synchronization has nothing to do with interfaces - you can add the "synchronized" keyword (to the implementation, not the interface) and you are still "implementing the interface". It's not a problem.
Deciding exactly where to synchronize, if at all, can be an important issue, and may be comples - but the interface has nothing to do with it.
 
Davidd Smith
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, jim
Thanks for answers. The synchronizing has no problem. But if I use RMI,
the Data class must throws RemoteException, do you think the RemoteException should be catched and thrown as RecordNotFoundException or RuntimeException? Could I update the DBAccess interface to throws RemoteException? The instructions says we "must implement the following interface", but does not say we can not change it, but it does explicitly say we can not change the "db.db".
Davidd
 
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 Davidd
I don't think you should change the interface.
You probably have some statement in your instructions that "Portions of your submission will be analyzed by software" or words to that effect. The only place where we can see this being implemented is where Sun know that you are implementing a certain interface (even then it has issues, but it is the only logical place). So if you change the interface, you run the risk that other code that is written to that interface will not work.
I commented to you in this thread that your networked code does not have to be a Data class - it can contain a Data class ("has a" versus "is a"). Therefore your networked code can implement a different interface than the Data class, and this other interface can be the one throwing the RemoteExceptions.
Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic