File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes extending the database class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "extending the database class" Watch "extending the database class" New topic
Author

extending the database class

vaibhav mishra
Ranch Hand

Joined: Jun 18, 2008
Posts: 168
I have instructions in my assignment that reads

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


but the class I extended is becoming too-much lengthy, 168 lines and I haven't even implemented single method given by the Sun's interface

since I know from my previous experience it'll soo become hard to manage if I have class much long(say 300 lines) what are the options I have, can I exetnd the Data.java class and provide added functionality, I don't understand what exctly they mean by data-access, is it the class which provides database connection or something else?

some of you suggested in this forum to extend the interface provided by sun , add additional methods required and then extend that interface to provide concrete class, is it going to violate the instructions given in my assignment?B&S 2.1.1

SCJP
Jason Moors
Ranch Hand

Joined: Dec 04, 2001
Posts: 188
Hi Vaibhav,

I think the requirement means that the data class must implement all the methods provided by the interface, but that doesn't mean ALL the code has to be in the data class, for example you could create additional classes for reading the file, locking mechanism etc and call from the data class.

The only reason to extend the interface or implement another interface is if you need to provide additional methods.

Regards,
Jason
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Hi Jason

Im my opinion...I dont see any problem to have a classe with moore than 500 lines of code...since it have a good organization !
JavaCod Conventions say the "files longer that 2000 lines are cumbersome"....that might be so long.....but 300 lines is very small too.....so you can have your avarage.

Fernando Franzini - Java Blog
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5608
    
  15

Hi vaibhav,

First of all: could you edit your first post and place the line you copied from the instructions.html between quote-tags (instead of code-tags), it will increase readibility of that line (and this thread).

Secondly you could create (if you want) a DBAccess class which accesses your database file and reads/writes records. Your Data class will have an instance of this class and the read (and other) method(s) of your Data class are just delegated to the DBAccess instance. As long as your Data class implements the given interface (directly or via an own created interface), it will be

And a final remark: my Data class counted 760 lines and 90% of them were code lines. I used only javadoc comments on the private methods, the public methods inherited the javadoc comments from the interface via {@inheritDoc}. And my own created interface counted in total 12 methods (including the ones inherited from the given interface) and 339 lines, so a whole lot of javadoc comments

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
vaibhav mishra
Ranch Hand

Joined: Jun 18, 2008
Posts: 168
@Jason

The only reason to extend the interface or implement another interface is if you need to provide additional methods.

this is the reason I want to do it.


@Fernando

I dont see any problem to have a classe with moore than 500 lines of code.


I agree with you but I am quoting this from my own experience, which was a long time ago and code was really ugly(maybe I am more matured now), maybe now I can manage a whole lot , thanks for pointing javadoc convention

@Roel

could you edit your first post and place the line you copied from the instructions.html between quote-tags (instead of code-tags), it will increase readibility of that line (and this thread).

done


Secondly you could create (if you want) a DBAccess class which accesses your database file and reads/writes records. Your Data class will have an instance of this class and the read (and other) method(s) of your Data class are just delegated to the DBAccess instance. As long as your Data class implements the given interface (directly or via an own created interface), it will be


I'was asking the same thing , thanks for answering, I'll do that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: extending the database class