0

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;
}

 }
someone
  • 6,577
  • 7
  • 37
  • 60

2 Answers2

1

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.

Community
  • 1
  • 1
Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
1

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.

user949300
  • 15,364
  • 7
  • 35
  • 66