Observer pattern RRS feed

  • Question

  • Hi all,

    I'm trying to use the observer pattern on updatng GUI controls.

    I have some controls (TextBoxes, Buttons)...

    I don't know how to link the Update method to the control. Is it possible to do that without inheret from the control and implement a new control includes the Update method.

    I have the IObserver (IGUI in my case) and ConcreteObserver (Control in my case)

    Any suggestions.

    Please help.


    Saturday, November 18, 2006 6:32 PM

All replies

  • Hi wasimf,

       I read your post but seems it lacks of details. I mean, imagine if I ask you "to go to the park, do I have to turn into left or into right?" (which park? where are you caming through? where are you coming from? those answers matter)

       In your context, "what observer is observing what subject" would be the question, in order to answer with accuracy

       But I found for you a series of articles, chapters, on the Observer pattern, that I suggest you as guidances and examples. Hopefuly you'll figure out how can you adapt these to your context, closing thus this thread (or, better, telling us "how did you solve your problem")

       The first series I show you I like better because isn't about the Observer as an isolated pattern. It's a common mistake trying to apply a pattern just to later claim you did it (in other words, applying a solution without checking first if it matches the problem you had)

    Discover the Design Patterns You're Already Using in the .NET Framework
    Design and Implementation Guidelines for Web Clients (will serve you even if your UI isn't web)
    Model-View-Controller (a holistic approach where Observer pattern could fit well in a wider context)
    Starting with Model/View/Controller (MVC) Architecture Pattern

       And finally, examples of the pattern itself

       Observer (patterns & practices' Enterprise Solution Patterns)
       Implementing Observer in .NET (attention: .NET 1.1)
       Exploring the Observer Design Pattern (an old but good, purist article)



    Sunday, November 19, 2006 4:08 AM
  • Thanks allot for your reply,

    I'll study all your links to be more smart.

    OK! I'll try to explain my context better.

    In general I'm working to design HMI application (Human machine interface: It's an application that gives the user interact with a machine,e.g: loggind data from the machine, operate things , alerts on things happen on the it and ...)

    I have a Tag class that deal with that data from the device on the machine, I mean reading data or writing data.

    My main problem is how to ling the Tag class to the GUI. Each Tag class values may be linked to one or more controls on the Forms controls. When the tag changes it's values the linked controls have to be changes.

    I want to make my applications two layers separately, first the GUI layer and second the machine real data witch deals with all the business logic to bring the data from the machine and vc.

    Sorry, I'm new on using design patterns, but this is the first time I really want to start programming in thinsa effective way.

    Best regards...


    Sunday, November 19, 2006 6:19 AM
  • That's fine, Wasimf

       In that case, your GUI controls should "suscribe" to the Tag classes in order to be alerted when a "data changed" event is published (possibly the Publish / Suscribe pattern, a close cousin of the Observer pattern, is better suited to implement what you need)

       There's no need to act in a 1:1 manner (I mean, you can have several controls tied to the same Tag and vice versa)

       Read the links I sent you to better understand how to implement that. Most of all, be as pragmatic as you can. Applying patterns is a plus, not a must. Your goal is to build a succesful application, yet

    Sunday, November 19, 2006 5:15 PM