I suggest to use an observer pattern. By using java.util.Observable
class (as subject) and the java.util.Observer
interface you will still keep the conventions.
- You create a concrete observer by subclassing java.util.Observer (GUI- Layer)
- You create a concreate Subject by subclassing java.util.Observable (DAO- Layer)
- You can attach your concrete observer to the concreate subject. (Referencing lower layers doesn't violate the convention!)
- A button click invokes the desired method (Business- or DAO- Layer) by delegating the concreate observer instance as type of java.util.Observer. So the DAO- Layer will never need to reference the GUI- Layer.
So the GUI calls a method like:
BusinessImpl#doDAOStuff(java.util.Observer observer){
...
dao.performStatements(observer);
....
}
And the DAO impl should look like:
DAOImpl#performStatements(java.util.Observer observer){
String stmt;
...
// do insert ...
observer.update(this, stmt);
...
// do update ...
observer.update(this, stmt);
...
}
It's just pseudo source, but I think it covers the main concept.