• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding to supplied interface

 
Mickey Mulligan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, is it cool for me to add new methods to the interface supplied with my SJDC assignment? At the moment the interface requires these methods to be implemented:

readRecord, updateRecord, deleteRecord, findByCriteria, createRecord, lockRecord, unlock

I'd like to add a further one: readFieldNames

This would return the field names for my records in a String array, removing the need to hard-code them anywhere. I suppose I could write this without having it in the interface, but I'd feel better with it in there...

So whadaya think?
 
Tim Fernandez
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mickey Mulligan:
Hi, is it cool for me to add new methods to the interface supplied with my SJDC assignment? At the moment the interface requires these methods to be implemented:

readRecord, updateRecord, deleteRecord, findByCriteria, createRecord, lockRecord, unlock

I'd like to add a further one: readFieldNames

This would return the field names for my records in a String array, removing the need to hard-code them anywhere. I suppose I could write this without having it in the interface, but I'd feel better with it in there...

So whadaya think?


Hi Mickey,

Adding methods to the supplied interface is a no-no.
But one way to do it without hurting the supplied interface is to create another interface which extends the supplied one. The newly created interface should contain the method you mentioned above. The class that does all the data file operations should then implement the new interface. Is this a requirement violation. I would say no, since you are still implementing the supplied interface indirectly:


Supplied interface
--New interface with additional method (extends)
--Implementing class (implements)

Hope this helps.
tim
 
Mickey Mulligan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll do that then, thanks.
 
Romeo Dickason
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mickey!

Why would you want to do that and risk failure? - what benefit will you gain from doing this, I can't see any real benefit, maybe I'm missing something?

Rather just have this method in you Data class.
 
Saheed Adepoju
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
In the instructions it says ...must implement the given interface... i will translate this to mean that, you can't add arguements to the given methods of the given DB but that doesnt explicitly stop one from adding more methods to the Data.java, pls i dont know if i am wrong, but i have coded with this impression. I dont think adding a method that reads something from the datafile ans stores it is a deviation from the instructions. Pls correct me if i am wrong..
 
Ronald Wouters
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

you don't risk anything by extending the supplied interface.
Below is an official reply from Sun dated February 7th, 2005.

Question 2: By stating that my Data class must implement the DB interface, does it mean DIRECT implementation? Am I allowed to create a subinterface of DB, and let the Data class implement that subinterface?

Reply from Sun Microsystems: Contrary to popular belief, this is actually legal. Implementation can be either direct or indirect, as long as your class implements it.


If you want to read all the rest of the questions and answers, below is the link for the relevant topic here on the ranch:

Official Replies from Sun Microsystems

Hope this helps
Regards, Ronald.
[ March 08, 2006: Message edited by: Ronald Wouters ]
 
Mickey Mulligan
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All this helps quite a bit, thanks muchly!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic