I am creating interface in Java for custom error handler.Want to pass an argument error object but I need it to be child of Exception class.Is it okay to use my defined class name in an interface ?Won't it make it less of an interface in terms of not being dependenton any implementation ?I try to do something like this:public class CustomException {    /* ... Implementation ... */}public interface Interface {    void onError(CustomException ex);}
Is it OK for interfaces to depend on concrete classes?
java;design;object oriented;interfaces
First I have to point out the fact that CustomException doesn't extend Exception so it is not really an Exception.That said:If you don't care about Dependency Inversion Principle, then leave it as it is. It's perfectly OK for an interface to depend on concrete classes, for example many interfaces depend on String or Object which are concrete classes. The thing is that we would tend to believe that classes that belong to the Java SDK are more stable (less prone to code-breaking changes) than the ones we write.In the other hand:If you want to follow the DIP (which has countless benefits and is my recommendation), then you have to do one of two things:Option 1Make CustomException abstractKeep void onError(CustomException ex) as it isOption 2Make CustomException an interfaceKeep void onError(CustomException ex) as it isWith either of those options you would be conforming to the DIP, since the interface would not depend on any concrete class, only on abstractions.In a direct application of dependency inversion, the abstracts are  owned by the upper/policy layers. This architecture groups the  higher/policy components and the abstracts that define lower services  together in the same package. The lower-level layers are created by  inheritance/implementation of these abstract classes or interfaces.  Martin, Robert C. (2003). Agile Software Development, Principles, > Patterns, and Practices. Prentice Hall. pp. 127131. ISBN  978-0135974445.