• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extra Method at Data.java

 
Song Jing Lim
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • 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?
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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:
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic