patterns - observer

J

Jimbo

Hi, I always seem to fall foul of the same issues when programming with a
user interface and that is showing/hiding controls depending on what the
user is doing.

Maybe it's the way I design my interfaces (web mostly) but I always end up
with what I consider a real mess of text1.visible = false stuff all over
the place, I hate it.

Anyway I was reading about the "Observer" pattern which to my mind seems to
be made for this type of scenario, but I cant seem to find a pratical
example of some working code.

So say I have a dropdown list with three items "1", "2" and "3" and each
specifies a text box to show with some info (drawn from a db) how would one
go about using the observer for this simple scenario? What messages would
be passed around to do the updates, etc?

You'll have to excuse if this is the wrong group but I tried the patterns
ng and it seems a bit dead.
 
T

TT \(Tom Tempelaere\)

Hi,

Jimbo said:
Hi, I always seem to fall foul of the same issues when programming with a
user interface and that is showing/hiding controls depending on what the
user is doing.
[...]

Define all states your UI component can be in. Then make a method
ChangeState, which adjusts the UI depending on the state. Then you only have
one method that does the hiding/displaying, enabling/disabling, etcetera of
the UI.
You'll have to excuse if this is the wrong group but I tried the patterns
ng and it seems a bit dead.

Then read the following book: 'Design Patterns - Elements of Reusable
Object-Oriented Software' by Erich Gamma, Richard Helm, Ralph Johnson and
John Vlissides (Adisson Wesley).

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top