• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Extending or expanding the DB interface.

 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The supplied interface (in my case DB.java) could be extended ( by inheritance ) by a subinterface containing any extra convenience methods I need.
Or I could define a new interface containing convenience methods and have my Data class implement both interfaces.
Are these possibilities acceptable?
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think both are good choices. What do you think the advantages of each are? Maybe jotting them down here will help decide which way you want to go?
All best,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a specific example (the more I read this assignment spec, the more weird it gets).
GUI: "It must allow the user to search the data for all records, or for records where the name and/or locationfields exactly match values specified by the user."
DB interface: public int[] find( String[] criteria )
"...A non-null value in criteria[n] matches any field value that begins with criteria[n]. ..."
So that leads me to desire an extra method: public int[] findExact( String[] criteria ); which returns only exact matches.
So I can choose to extend the DB interface:
interface DBEnhanced extends DB and then define the new method findExact as a member of DBEnhanced. The class Data would then implement DBEnhanced (and by inheritance DB).
Or I can define a new interface DBEnhanced and do class Data implements DB, DBEnhanced.
I can see the need for some more "useful" methods.
My main worry is whether either use of the extended interface goes against the requirement "Data must implement the interface DB"? That is, is only class Data implements DB acceptable?
[ April 13, 2003: Message edited by: Barry Gaunt ]
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hm...interesting question. I would suggest that, so long as you're implementing the interface, as is, you're ok.
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
 
Perry Board
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Barry Gaunt:
I have a specific example (the more I read this assignment spec, the more weird it gets).
GUI: "It must allow the user to search the data for all records, or for records where the name and/or locationfields exactly match values specified by the user."
DB interface: public int[] find( String[] criteria )
"...A non-null value in criteria[n] matches any field value that begins with criteria[n]. ..."
...
My main worry is whether either use of the extended interface goes against the requirement "Data must implement the interface DB"? That is, is only class Data implements DB acceptable?

Barry, I just got my assignment and had the same questions as you. Noticed you posted this a few weeks ago. Did you come to a conclusion?
It gets down to the meaning of "implement the interface." Does this mean we must provide a partial-match search algorithm, even if the GUI will only use an exact match search? For that matter, should we put any code into methods for create and delete if the client has no option to do so? I've seen other people posting that they won't be implementing create and delete methods, other than possibly throwing exceptions.
Just seems a little unfinished to say you have implemented an interface, but haven't provided any code for several of the methods. A more complete solution seems to be to implement all of the methods fully, even if the GUI will only use some of them. Thoughts?
 
S. Ganapathy
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Barry, Max,
I am thinking to implement the interface given (DBAccess.java) in Data.java (implements DBAccess), and those convinent methods in Data.java. Locking mechanism, I want to implement in an inherited class from Data.java (Do nothing implementation for locking mechanism in Data.java). This is to provide locking mechanism only for network clients, not to standalone client.
Apart from the interface provided by SUN, I want to create an interface called Client.java with the following methods:
public interface Client {
    public Collection getAllContractors();
    public ContractorInfo getContractor(long recordNo) throws RecordNotFoundException;
    public void bookContractor(ContractorInfo info) throws SecurityException;
    public Collection findByCriteria(String[] criteria);
}
RemoteClientImpl implements RemoreClient
RemoteClient extends Client, Remote
RemoteData extends Data
Please let me know your comments.
Ganapathy
[ May 05, 2003: Message edited by: S. Ganapathy ]
[ May 05, 2003: Message edited by: S. Ganapathy ]
 
Larry Li
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I prefer to use ComboBox for criteria search on client side. The names and locations that the user could search are only selected from the list, "any" is supported. So we get it, "Exactly match" is controlled by items we add to the ComboBox.
But the problem about extending the interface is still there: I want to add another method:
getDistinctColumnValue()
to get all search items.
 
Perry Board
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know about that combobox idea. Sure it might works fine for our tiny little sample data file, but what if there were two hundred different cities? And your server would have the added responsibility to notify all clients when a record is added, so the GUI can adjust its combo box options. I think a simple text field search is much better.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic