Reputation: 6572
My Interface and implementation is in same package and I used ISessionDAO for interface and SessionDAOImpl for the implementation. Is this best/standard way to define interface and class or do i need to define separate package for implementation.
Interface
package com.tolo.subca.bank.session;
public interface ISessionDAO {
public boolean checkForSingleOrMultiple(String originator);
}
Class
package com.tolo.subca.bank.session;
public class SessionDAOImpl implements ISessionDAO {
@Override
public boolean checkForSingleOrMultiple(String originator) {
// TODO Auto-generated method stub
return false;
}
}
Upvotes: 0
Views: 105
Reputation: 234795
There's nothing at all wrong with defining an interface and an implementing class (or classes) in the same package.
The interesting question is: how do you decide what goes in one package and when you need different packages for different parts of your code. There are lots of discussions about this. Some interesting resources are:
Search for "java package design" for lots more on this topic.
Upvotes: 1
Reputation: 15729
Varies by organization. We used to put the implementations into a subpackage, com.company.foo.impl, but there is no right or wrong. I don't think you need both a leading I on the interface AND a trailing impl.
Upvotes: 1