• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S: DBMain & Data

 
Laura Pecoraro
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9934
113
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Laura Pecoraro
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic