简体   繁体   中英

best/standard way to define interface and class

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

 }

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM