wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes If I don't need the delete and create functions, what to do with the interface given Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "If I don Watch "If I don New topic

If I don't need the delete and create functions, what to do with the interface given

Lucas cotta

Joined: Oct 10, 2011
Posts: 21
Hi all!

My instructions do not require create or delete in the GUI, so I assume I don't need to implement the create and delete methods of the given interface.
But if this is true, what should I do in the class that implement the interface? Just return null?
I'm worried about "must implement this interface" means that I must implement all methods...
Did anyone loose points with this?

arvind kushwaha
Ranch Hand

Joined: Aug 12, 2011
Posts: 32

Luscas cotta.

If you implements any class you have to provide implementation of all the method. If you think that this method is not full filling your need then donot write any think in body or donot implements the interface
James Boswell

Joined: Nov 09, 2011
Posts: 1012

A better solution IMO is to throw an UnsupportedOperationException for methods not implemented by the concrete class.
Matthew Brown

Joined: Apr 06, 2010
Posts: 4344

Check the instructions carefully, though. Yours may be different, but mine required me to implement the interface fully regardless of which methods were needed by the application.
Roel De Nijs

Joined: Jul 19, 2004
Posts: 5147

You could take a risk and implement the given interface and for each method you don't use in the application throw an UnsupportedOperationException. Then extensively document in choices.txt why you followed this approach and you might pass with this approach. But it still is a risk you could possibly fail for not having an actual implementation for all methods. As far as I know no one so far took this risk, because it could be a costly one.

Hope it helps!
Happy New Year!

SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
Lucas cotta

Joined: Oct 10, 2011
Posts: 21
I will implement all methods, then. I won't take any risks!
Thank you all for the replies!!
Anayonkar Shivalkar

Joined: Dec 08, 2010
Posts: 1502

Hi Lucas,

I agree with Roel. It is indeed risky to have an empty implementation.

For me too, requirements were similar (no necessity for create and delete operations, but given interface was containing those methods).

So, I wrote a descent working code for those methods, but did not expose those methods via RMI or did not provide any buttons on GUI. So, only way to invoke those methods was to write another class and call the methods.

Of course, I mentioned all these things in choices.txt.

All the best!

Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Don't get me started about those stupid light bulbs.
subject: If I don't need the delete and create functions, what to do with the interface given
Similar Threads
Leaving the provided interface comments unchanged?
SCJD - Create & Delete
NX: DuplicateKeyException
B&S : User Interface
Question about GUI