Observer Pattern confusion

If i have a GUI builder which builds my first interface and to that interface I attach an observer which detects when a certain field in that interface is updated then do I have to do one of the following;

1) create interface1 from builder and then attach an observer so as the builder can know when a certain task has completed 2) Do i just create an observer and then the observer creates the interface?

Basically i am trying to create an interface from builder, which then, on a button click goes and gets some data. When this data has been retrieved i want to let the builder class know so it can proceed to use it to build interface 2. I am trying to user the observer design pattern to do this.

Thanks

Answers


You should create the interface, then add (or register/attach) the relevant observers afterward. Something like (in pseudocode);

GUI mygui = GUIBuilder.createNewGUI();

ButtonListener OK = new OKButtonListener();
ButtonListener Cancel = new CancelButtonListener();
DataListener dataReady = new dataReadyListener();

mygui.registerButtonListener(OK);
mygui.registerButtonListener(Cancel);
mygui.registerDataListener(dataReady);

mygui.show();

If all the GUIs you are building will have the same listeners attached, you can have the interface builder create and attach the listeners for you as well.


Need Your Help

How to attach stylesheet to HTML email?

html css email

I want to include normalize.css in a HTML email. However various tutorials advise that all css should be inline, as some email clients ignore linked styles in the head. In such case how can I include

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.