java - 3-tier architecture - Notify gui from lower layers -


i creating 3 tier application in java consists of gui, business logic layer , database layer. layers client-sided.

from definition of multi tier architecture allowed make calls same or lower layers , return same or higher layers.

in case i'm doing lot of database queries after user clicked on button. have status field in gui queried table shown.

because layers in same application, call method database layer while looping through tables update status field. doing break rule make calls lower or same layer.

so "legit" way update or notify gui lower layers in 3 tier architecture?

i suggest use observer pattern. using java.util.observable class (as subject) , java.util.observer interface still keep conventions.

  1. you create concrete observer subclassing java.util.observer (gui- layer)
  2. you create concreate subject subclassing java.util.observable (dao- layer)
  3. you can attach concrete observer concreate subject. (referencing lower layers doesn't violate convention!)
  4. a button click invokes desired method (business- or dao- layer) delegating concreate observer instance type of java.util.observer. dao- layer never need reference gui- layer.

so gui calls method like:

businessimpl#dodaostuff(java.util.observer observer){     ...     dao.performstatements(observer);     .... } 

and dao impl should like:

daoimpl#performstatements(java.util.observer observer){     string stmt;     ...      // insert ...     observer.update(this, stmt);      ...     // update ...     observer.update(this, stmt);      ... } 

it's pseudo source, think covers main concept.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -