• 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

Extra Method at Data.java

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So far as I know, beside implement methods define at DBMain.java, we can create few method at Data.java.

But can I use that method by other class?

Let say I got a DataAdaptor as below:

Public Class DataAdaptor{
DBMain data = null;
pubic DataAdaptor(String dbpath){
data = new Data(dbpath);
}
}

Can I just define data as Data type instead DBMain? E.g.
Public Class DataAdaptor{
Data data = null;
pubic DataAdaptor(String dbpath){
data = new Data(dbpath);
}
}

So I can use those extra method define at Data.java which didn't define at DBMain interface e.g.
data.newmethod()

Any help on this?
 
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Nobody forbid you to implement other interface, or to add new methods on you Data class (or at least like this is in my specs).

Regards M.
 
Song Jing Lim
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply...

But is that any limitation that I can only add private method to Data.java? if I add extra public method (e.g. getNumberOfRec()) for Data.pub, then I only can instantate Data object as below:

Data db = new Data(dbpath);

instead of

DBMain db = new Data(dbpath);

Is that necessary to instantate db object as DBMain?

The public method I plan to implement include retrieve record version (using timestamp) by adaptor class:

So if

Class Adaptor(){

DBMain db = new Data(dbpath);

public int updateRec(Subcontractor obj){
String objVersion = obj.getVersion();
int recNo = obj.getRecNo();
String recVersionInDb = db.getRecVersion(recNo);
if(objVersion.equalIgnoreCase(recVersionInDb)){
....
}
}

I not able call db.getRecVersion(recNo) if db is DBMain object. I can only call that method if:
Data db = new Data(dbPath);

Back to my original question:
Any one pass SCJD by instantate db in adaptor class:
Data db = new Data(dbPath);

Or every one just do like:
DBMain db = new Data(dbPath);

Please help... :roll:
 
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic