J
josh
Hello there,
I have question about application design (client side).
The problem is I have declared some basic interface for GUI form's
models, like this:
public interface BasicModel<K> {
/*...other stuff... */
public void setEntityId(K id);
public void edit();
public void refresh();
public void save();
public void search();
}
But now I see this is not enough, because I would like my basic actions
throws some exceptions like: EntityNotFoundException or
EditNotAllowedException or something like this.
My question is: can I declare and implement that exceptions inside this
interface as public static classes? Yes, I know Java would not stop me,
this is legal to do so, but is that good solution? Look at this:
public interface BasicModel<K> {
/*...other stuff... */
public void setEntityId(K id)
throws BasicModel.EntityNotFoundException;
public void edit()
throws BasicModel.SomeOtherException;
public void refresh();
public void save();
public void search();
public static class EntityNotFoundException extends Exception {
/* some constructors or other methods */
}
/* other exceptions' classes */
}
My explanation for this is that these Exceptins are part of that
particular interface, so why not declaring them here? On the other hand
I have never seen such interfaces, so maybe this is stupid idea? What
you think? Should I declare them in separate classes? Why yes, why not?
I have question about application design (client side).
The problem is I have declared some basic interface for GUI form's
models, like this:
public interface BasicModel<K> {
/*...other stuff... */
public void setEntityId(K id);
public void edit();
public void refresh();
public void save();
public void search();
}
But now I see this is not enough, because I would like my basic actions
throws some exceptions like: EntityNotFoundException or
EditNotAllowedException or something like this.
My question is: can I declare and implement that exceptions inside this
interface as public static classes? Yes, I know Java would not stop me,
this is legal to do so, but is that good solution? Look at this:
public interface BasicModel<K> {
/*...other stuff... */
public void setEntityId(K id)
throws BasicModel.EntityNotFoundException;
public void edit()
throws BasicModel.SomeOtherException;
public void refresh();
public void save();
public void search();
public static class EntityNotFoundException extends Exception {
/* some constructors or other methods */
}
/* other exceptions' classes */
}
My explanation for this is that these Exceptins are part of that
particular interface, so why not declaring them here? On the other hand
I have never seen such interfaces, so maybe this is stupid idea? What
you think? Should I declare them in separate classes? Why yes, why not?