• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Clarification on assignment- implementing the interface

 
Ranch Hand
Posts: 81
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greg Funston
Ranch Hand
Posts: 81
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 81
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Robert for the prompt reply.

Cheers,
Greg Funston SCJP
 
Ranch Hand
Posts: 590
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic