| 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: 4355
|
|
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
|
 |
 |
|
|
subject: B&S: DBMain & Data
|
|
|