Topic: 偶想定义一个接口,请问这么写对吗?

  Print this page

1.偶想定义一个接口,请问这么写对吗? Copy to clipboard
Posted by: lxymerry
Posted on: 2005-10-09 12:56

interface DBOperation()
{
  public Connection getConn() throws SQLException;
  public Object execPro(String strProName)throws SQLException,IOException;
  public int execSQL(String strSQL) throws SQLException;
  public ResultSet getQueryResult(String strSQL) throws SQLException;
  public String getXmlByResultSet(ResultSet rs) throws SQLException;
}编译时,总告诉我缺少;号

2.Re:偶想定义一个接口,请问这么写对吗? [Re: lxymerry] Copy to clipboard
Posted by: why
Posted on: 2005-10-09 21:57

interface DBOperation // no () required.

I'm wondering whether you should make DBOperation public -- but not its methods.

3.Re:偶想定义一个接口,请问这么写对吗? [Re: lxymerry] Copy to clipboard
Posted by: bluecrystal
Posted on: 2005-10-09 23:47

ft,晕倒了
Dead

4.Re:偶想定义一个接口,请问这么写对吗? [Re: lxymerry] Copy to clipboard
Posted by: lizhihua
Posted on: 2005-10-10 12:45

定义接口不能用()这 一对小括号的,接口是一个特殊的抽象类,所以要和定义类的规则一样。如果定义为了接口,类体中的方法也可不必要加public 关键字(最好不加,个人意见),默认就是公有的。TongueTongueTongueTongueTongue

5.Re:偶想定义一个接口,请问这么写对吗? [Re: lxymerry] Copy to clipboard
Posted by: lxymerry
Posted on: 2005-10-10 17:23

啊~~,,谢谢各位大虾的关注,听完各位高手们的评论, 小弟果然明白了很多,谢啦 ~~

6.Re:偶想定义一个接口,请问这么写对吗? [Re: lxymerry] Copy to clipboard
Posted by: 2352439
Posted on: 2005-10-11 13:46

标准的接口定义:
interface PCI
{
void get();
}

7.Re:偶想定义一个接口,请问这么写对吗? [Re: lxymerry] Copy to clipboard
Posted by: wallacer
Posted on: 2005-11-09 17:10


public interface DBOperation
{
public Connection getConn() throws SQLException;
public Object execPro(String strProName)throws SQLException,IOException;
public int execSQL(String strSQL) throws SQLException;
public ResultSet getQueryResult(String strSQL) throws SQLException;
public String getXmlByResultSet(ResultSet rs) throws SQLException;
}


这样就OK了!

8.Re:偶想定义一个接口,请问这么写对吗? [Re: lxymerry] Copy to clipboard
Posted by: ftang
Posted on: 2005-11-10 04:26

This is the worst Database interface design I ever seen, forget about the syntax problem, this interface design is totally disaster:

1. expose the connection --> getConn(), the major idea of DAO object is make the database connection transparent to the users. if expose the getConection to user, what connection u gonna use when client call execSQL method?

2. int execSQL() usually we don't primitive type on interface, because Object is more "coarse" granuality

3.ResultSet getQueryResult, when you expose the result set to client, have you thought how to recycle it? common sense, when using resultset, the db connection must be open.

4 String getXmlByResultSet why the return type is "String" not "DOM" object? the return type of a interface should be accurate.

5. throw SQLException, you design the DB wrapper, so this database related exception should be handled internally, what u expect user to do when user got "SQLException"? if user can't "recover" from the exception(because you should handle the it) they should not see these exception on interface.

general speaking: Syntax error is easy to fix...design error cost much more than you can image to fix...


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923