Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interface & Implementation class location

 
Joe Paolangeli
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a question for folks that create interfaces and implementing classes. Do you keep the interface and the implementing class in the same or different packages?
 
Ramesh Donnipadu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you can do it either way.
If you choose to write the interface in a different package, you just need to import it before using it.
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have seen it done both ways. I tend to mix interfaces and classes into the same packages but this may not be a best practice.
John
 
Laojar Chuger
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you guys ever see private or protected interface?
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interfaces can only be public or default/package/friendly, ie,
public interface Example
or
interface Example
John
 
Mark Herschberg
Sheriff
Posts: 6037
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joe Paolangeli:
This is a question for folks that create interfaces and implementing classes. Do you keep the interface and the implementing class in the same or different packages?

It really depends on your design. If everything relating to this concept is small and local, you should probably keep them in one package. If the interface has multiple, widely differing implementations, it make mare more sense to put them in different packages. I've done projets where we create a facade and use package level protection to prevent people from going behind the facade, in thise case, the interface and implementation are in different packages.

--Mark
hershey@vaultus.com
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic