Observer Pattern

Yesterday I was reading some article about AOP and OOP concepts. Article has some discussion about Observer pattern, then I thought lets read about this first and then move further. I found this small example and one line definition on wiki which helped me.
In observer pattern “one or more objects (called observers or listeners) are registered (or register themselves) to observe an event which may be raised by the observed object (the subject). (The object which may raise an event generally maintains a collection of the observers.)”.

I always like the learn from practicals rather than to read tons for theory pages. Following is the the small code which cleared my concepts about this pattern :

Simple Pseudo code for Observer Pattern In Python :

class Listener:

def initialise (self, subject):

subject.register(self)

def notify (self, event):

event.process()

class Subject:

def initialise (self):

self.listeners = []

def register (self, listener):

self.listeners.append(listener)

def unregister (self, listener):

self.listeners.remove(listener)

def notify_listeners (self, event):

for listener in self.listeners:

listener.notify(event)
subject = Subject()

listenerA = Listener()

listenerB = Listener()

subject.register(listenerA)

subject.register(listenerB)

#the subject now has two listeners registered to it.

3 Responses to “Observer Pattern”

  1. CHARLIE says:


    CheapTabletsOnline.Com. Canadian Health&Care.Special Internet Prices.Best quality drugs.No prescription online pharmacy. High quality drugs. Order pills online

    Buy:Advair.SleepWell.Zocor.Acomplia.Amoxicillin.Female Pink Viagra.Cozaar.Female Cialis.Ventolin.Nymphomax.Zetia.Aricept.Wellbutrin SR.Buspar.Lipothin.Lasix.Benicar.Prozac.Lipitor.Seroquel….

  2. DARYL says:


    CheapTabletsOnline.Com. Canadian Health&Care.Best quality drugs.Special Internet Prices.No prescription online pharmacy. Online Pharmacy. Buy drugs online

    Buy:Prozac.Wellbutrin SR.Acomplia.Zetia.Lipitor.Seroquel.Benicar.Amoxicillin.Aricept.SleepWell.Buspar.Zocor.Female Cialis.Lipothin.Female Pink Viagra.Ventolin.Advair.Lasix.Cozaar.Nymphomax….

  3. ALEJANDRO says:


    CheapTabletsOnline.com. Canadian Health&Care.Best quality drugs.Special Internet Prices.No prescription online pharmacy. Low price pills. Order drugs online

    Buy:Advair.Benicar.Female Pink Viagra.Wellbutrin SR.Seroquel.Ventolin.Amoxicillin.Acomplia.Aricept.Prozac.SleepWell.Lipothin.Zetia.Buspar.Lasix.Cozaar.Zocor.Female Cialis.Lipitor.Nymphomax….

Leave a Reply