Interfaces are very useful for imposing class & method signatures on implementing classes - i.e. to make sure all your DAOs have the same methods available which allows you to handle DAOs generically when desirable.

However I have never come across a situation where anybody has changed the implementation when doing an upgrade to their application. It sounds good, but IMHO, never happens. Would be interested to find out otherwise :)

Another point against interfaces, especially if you have specific interfaces for each implementation such as I have in my current project, it makes it a PITA to follow the code in Eclipse. Each time I come across an interface, I can't go any further with the 'open declaration' Eclipse function but have to go off and find and open the implementation manually.

On 10/08/2004 03:21 PM Marco Mistroni wrote:
Hello,
        My 2 cents.. go for the interface... it will make your life
Easier for the future when you want to change implementation....

Regards
        marco

-----Original Message-----
From: atta-ur rehman [mailto:[EMAIL PROTECTED] Sent: 08 October 2004 15:13
To: Struts Users Mailing List
Subject: [OT] Request for comments on DAO pattern implementation


Dear all,

I've contemplated two ways of implementing DAO pattern; and I'm unable
to decide which is better :) Any comments on pros and cons of these
two approaches will be greatly appericiated.

Implementation 1: Have IDAO interface and let all the DAO objects
implement this interface; with probably an abstract class in between.
Every method need to cast Object down to its relevant DTO and throw
exception if the DTO is not of expected type.

public interface IDAO {

  Object findByPrimaryKey(final Object key);
  Collection findByCriteria(final String whereClause);
  Object insert(final Object o);
  void delete(final Object o);
  void update(final Object o);
  Collection getAll();
}

public class FooDAO implements IDAO {
......
}

Or  approach 2: every DAO is a class of its own with all the methods
only accepting the expecting DTOs!

public class FooDAO {

Foo findByPrimarykey(Object pk);
insertFoo(Foo);
deleteFoo(Foo);
updateFoo(Foo)
Collection getAll();
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to