• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

add new method in Interface DB

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public interface DB {

public String[] read(int recNo) throws RecordNotFoundException;

public void delete(int recNo, long lockCookie) throws RecordNotFoundException, SecurityException;

public void update(int recNo, String[] data, long lockCookie) throws RecordNotFoundException,
SecurityException

public int[] find(String[] criteria);

public int create(String[] data) throws DuplicateKeyException;

public long lock(int recNo) throws RecordNotFoundException;

public void unlock(int recNo, long cookie) throws RecordNotFoundException, SecurityException;
}

In the interface given by SUN, only seven methods are declared.
Can I insert my own method in this interface, such as

public List<ContractorClass> readAll() throws IOException;

If you can let me know asap, it would be really appreciated.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello "PaulSeldon07"-

Welcome to JavaRanch.

On your way in you may have missed that we have a JavaRanch Naming Policy for displayed (screen) names. Your displayed name must consist of a first name (or an initial), a space, and a family name (in that order) and not be obviously fictitious. Since yours "PaulSeldon07", does not conform with it, please take a moment to change it, which you can do right here.

Posters with nonconforming displayed names will be locked out of JavaRanch after a few posts using those names.

Thanks
-Barry

P.S. surely plain "Paul Seldon" will do the trick?

(NR) - search tag
[ January 31, 2007: Message edited by: Barry Gaunt ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot add anything to the interface - but I guess you can extend it. Make sure that the original given interface is properly implemented though.

You mayfind it beneficial to search the forum for similar questions. For example:

A past discussion on this topic.
[ January 31, 2007: Message edited by: Barry Gaunt ]
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think any changes are wise, even extending the interface.

A method returning a List of type Contractor is at a higher level of abstraction than the Sun provided interface.

AFAIK, in order to execute readall/findall, the find(String[]) should return all results if all elements of the array passed in are null;
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by PaulSeldon07:

In the interface given by SUN, only seven methods are declared.
Can I insert my own method in this interface, such as

public List<ContractorClass> readAll() throws IOException;

If you can let me know asap, it would be really appreciated.



No, I wouldn't do. And it is not necessary. I think if you find it necessary, then there is something wrong with your design. I see what you are driving at, and what I've done is create another class that handles the abstraction (with a ContractorClass, etc.) and that calls the low level Data that implements the Sun interface as given. Then you make use of your class with higher level of abstraction from the client/server side.

-- Vince
 
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Barry Gaunt:
You cannot add anything to the interface - but I guess you can extend it. Make sure that the original given interface is properly implemented though.

You mayfind it beneficial to search the forum for similar questions. For example:

A past discussion on this topic.

[ January 31, 2007: Message edited by: Barry Gaunt ]



I have extended DB interface and added two methods to new interface. Now Data class will implement new interface with additional methods. You can add more methods to new interface (which extends DB) as per your requirement.

I know many people on this forum has done this and my assignment doesn't say you have to implement DB directly in Data class.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I know many people on this forum has done this and my assignment doesn't say you have to implement DB directly in Data class.[/QB]


You can't if it says this:

"Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:

package suncertify.db;
public interface DB"
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Brian Kelly:

You can't if it says this:

"Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:

package suncertify.db;
public interface DB"



Yes my assignment says the same...

My new interface call ReadXY.java which extends DB.java also in same package. In that case why I can't use it? I mean Data.java is implementing DB.java methods plus some other methods from ReadXY.java interface as well...

thank you
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also refer to following thread where people pass with above solution..

https://coderanch.com/t/186750/java-developer-SCJD/certification/Extending-DB-Interface

just plain OO design from my point of view..

I mean it will be shocking if SUN has script which reads

if (Data extends DB){
PASS;
} else {
NO MATTER WHAT YOU ARE FAIL. EVEN YOU IMPLEMENTED INDIRECTLY.
}



[ February 01, 2007: Message edited by: Ken Boyd ]
[ February 01, 2007: Message edited by: Ken Boyd ]
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this thread is more informative compare to above

https://coderanch.com/t/186750/java-developer-SCJD/certification/Extending-DB-Interface
 
Brian Kelly
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ken Boyd:
[QB]You can also refer to following thread where people pass with above solution..

https://coderanch.com/t/186750/java-developer-SCJD/certification/Extending-DB-Interface

just plain OO design from my point of view..

I mean it will be shocking if SUN has script which reads


It does say " Portions of your submission will be analyzed by software; where a specific spelling or structure is required, even a slight deviation could result in automatic failure."

Perhaps it's okay, but I'm not taking any risks with any "must"...
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Brian Kelly:

It does say " Portions of your submission will be analyzed by software; where a specific spelling or structure is required, even a slight deviation could result in automatic failure."

Perhaps it's okay, but I'm not taking any risks with any "must"...



Yeah that is jar file name and directory structure and also file names like Data etc.. not the design part if I am not wrong..
[ February 01, 2007: Message edited by: Ken Boyd ]
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please someone who pass recently or our guru Andrew can confirm. It will be of great help.

Thank you
 
Vincent Li
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand why this issue keep coming up over and over. Why do people keep wanting to change the interface when ultimately, your Data.java will have to implement all these String[] methods anyway?

IMHO, may be many people's impression is that your client will call these methods directly somehow and it doesn't look nice. You'd want to call something like "List<Record> search(Criteria)" versus "long[] findRecord(String[])". That's fine. The two are really separate things. It seems like a straightforward OO desing to have one call the other. Your client sees the high level one and you access the database with the Sun provided one.

It seems there are a few general alternatives here:

1) Extend the DBAccess interface:
interface MyDBAccess extends DBAccess {}
class Data implements MyDBAccess {}

2) Implement additional inteface directly:
class Data implements MyDBAccess, DBAccess {}

3) Use the adapter:
class Data implements DBAccess
class MyAdapter {
Data dataInstance;
}

3a) Adapter with an interface (Delegate?):

class Data implements DBAccess {}
interface MyDBAccess {}
class MyAdapter implements MyDBAccess {
Data dataInstance;
}

Personally, I opt for 3/3a as a better OO design in that it never exposes any of the Data/DBAccess stuff to the rest of the world (encapsulation). It seems pretty obvious to me. But that's just my opinion.

-- Vince
SCJP(1.4), SCWCD(1.4), SCJD (almost there!)
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Ken Boyd]:

I know many people on this forum has done this and my assignment doesn't say you have to implement DB directly in Data class.[/QB]

[Brian Kelly]:

You can't if it says this:

"Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:

package suncertify.db;
public interface DB"


If Data implements MyDB and MyDB extends DB, then Data implements DB. Simple. If you want to assume that Sun's testers might not grasp this point (or can't write a decent automated test for this) then you can make it more obvious by writing

Such a redundant declaration is perfectly legal, if a bit silly. But if it alleviates some concerns, what the heck...
[ February 02, 2007: Message edited by: Jim Yingst ]
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jim Yingst:
[Ken Boyd]:

I know many people on this forum has done this and my assignment doesn't say you have to implement DB directly in Data class.

[Brian Kelly]:

You can't if it says this:

"Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:

package suncertify.db;
public interface DB"


If Data implements MyDB and MyDB extends DB, then Data implements DB. Simple. If you want to assume that Sun's testers might not grasp this point (or can't write a decent automated test for this) then you can make it more obvious by writing

Such a redundant declaration is perfectly legal, if a bit silly. But if it alleviates some concerns, what the heck...

[ February 02, 2007: Message edited by: Jim Yingst ][/QB]



Thanks Jim. It will be big surprise if SUN writes (they can no question about that) scripts to check Data extends DB but play safe with $400 investment
 
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic