aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S: DBMain & Data 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 "B&S: DBMain & Data" Watch "B&S: DBMain & Data" New topic
Author

B&S: DBMain & Data

Laura Pecoraro
Ranch Hand

Joined: Mar 31, 2009
Posts: 45
Hi all and goodday (buongiorno ),
a question: my sun specification say to implements the DBMain interface by Data class... ok, this is a easy, but I can add personal methods in this class (es. getDatabaseName()) or not?? The Data class must "map" exactly the interface or not???

In the specification don't say about a Logs management... I must implements this or its optional functionality???

Thanks, Laura
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5286
    
  13

Hi Laura,

If it's not a must requirement, you have the choice to implement a log-management or not. That's completely up to you

You can add personal methods to your Data class, but you will get compiler errors if you try to access these records through an interface reference


you could solve this, by following code


but that's also a problem to future enhancements: if you or another developer creates a DataMySQL-class (which accesses a MySQL-db) which implements the DBMain interface, you or he/she will have to do a lot of changes: replace all Data-occurences with DataMySQL, he/she isn't aware of your extra methods (therefor you should always try to program as much as possible against interfaces), so that will give a lot of compiler errors (and extra work) too,...

so the best way is to create your own interface LaurasDBMain and extend from DBMain and then add your own methods in your interface. The Data-class will implement LaurasDBMain and that will solve all issues. Your code would look like this:


Good luck,
Roel


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

Joined: Mar 31, 2009
Posts: 45
Thanks about your answer

Laura

Roel De Nijs wrote:Hi Laura,

If it's not a must requirement, you have the choice to implement a log-management or not. That's completely up to you

You can add personal methods to your Data class, but you will get compiler errors if you try to access these records through an interface reference


you could solve this, by following code


but that's also a problem to future enhancements: if you or another developer creates a DataMySQL-class (which accesses a MySQL-db) which implements the DBMain interface, you or he/she will have to do a lot of changes: replace all Data-occurences with DataMySQL, he/she isn't aware of your extra methods (therefor you should always try to program as much as possible against interfaces), so that will give a lot of compiler errors (and extra work) too,...

so the best way is to create your own interface LaurasDBMain and extend from DBMain and then add your own methods in your interface. The Data-class will implement LaurasDBMain and that will solve all issues. Your code would look like this:


Good luck,
Roel
 
wood burning stoves
 
subject: B&S: DBMain & Data