my dog learned polymorphism*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Clarification on assignment- implementing the interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Clarification on assignment- implementing the interface" Watch "Clarification on assignment- implementing the interface" New topic
Author

Clarification on assignment- implementing the interface

Greg Funston
Ranch Hand

Joined: Feb 09, 2011
Posts: 81

Ok, I have the urlybird assignment and I think I know the answer to this question but because the assignment uses
an auto checker it is important to understand the requirement for submission exactly.

The assignment states "Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:

package suncertify.db.

If I take this literally this means that my Data class should be:

public class Data implements DB{

Am I allowed to deviate from this and make the class

public class Data implements DbExtendedInterface{

where DbExtendedInterface is an extension of DB such that

public interface DbExtendedInterface extends DB {}.

Through the rules of inheritance DB is still implemented by the Data class and from what I have read elsewhere I expect this is acceptable.
Thanks.

Greg Funston SCJP

Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5233
    
  12

Of course, many people did that. Extending the required interface is a proven approach. Using the search engine, you'll find plenty of threads about this topic all with the same conclusion: you can extend the given interface.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2265
    
    3

Howdy, Greg!

So champ, the question is if you are allowed to extend the interface provided by Sun and have the Data class implement this interface? The answer is yes. No need to worry. I'd say that 99% of the candidates do that.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Greg Funston
Ranch Hand

Joined: Feb 09, 2011
Posts: 81

Thanks guys, much appreciated.

I have another simple design question. The one method in the interface is:

public String[] read(int recNo)throws RecordNotFound Exception;

It's purpose is:

"Reads a record from the file. Returns an array where each element is a record value"

If the class implements this interface must I use this method or may I design my own methods to substitute for this method with a different return type to accomplish the same basic operation. For example lets say I want to use Collections where I can move data using objects. Is this allowed or am I stuck with using arrays to move data around?

Thanks.
Greg Funston SCJP
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2265
    
    3

Hey, partner.

You can put all methods you judge necessary in the interface that extends the interface provided by Sun and use them. However, you still have to implement all methods of the provided interface, even create and delete, which you'll never have to call anywhere in your application.
Greg Funston
Ranch Hand

Joined: Feb 09, 2011
Posts: 81

Thanks Robert for the prompt reply.

Cheers,
Greg Funston SCJP
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

Greg Funston wrote:If the class implements this interface must I use this method or may I design my own methods to substitute for this method with a different return type to accomplish the same basic operation. For example lets say I want to use Collections where I can move data using objects. Is this allowed or am I stuck with using arrays to move data around?


What would be the general consensus on this approach - good idea or bad idea? Have many people taken this approach?


SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5233
    
  12

I kept the original methods and thus worked with String[] in the Data class. In my business service implementations I did the conversion back and forth between String[] and my transfer (value) object.

It's just your own decision, there is no good or bad.
 
 
subject: Clarification on assignment- implementing the interface