SlideShare a Scribd company logo
QmPe
                                                initiative




OBSERVER PATTERN explained !




                                 Prepared by Annamalai C


           Copyright 2006-2011
Observer Pattern in Real Life
There is always a Observer and Observable object around you.
You are an Observer, TV is an Observable Object.
-----------------------------------
Ideology of Observer Pattern is something close.
-----------------------------------
Colloquially Observers are called as Listeners
                Observables are called as Providers




             Observable                                Observer




                                Copyright 2006-2011
Observer Pattern in Java




Observable Objects are called as Subject.




                                            Copyright 2006-2011
Real Life vs Java Object




                                                 Observer




                           Copyright 2006-2011
Real Life vs Java Object




           Observable




                           Copyright 2006-2011
How Observer Pattern works in Real Life ?



                                         1
                                 Register/ Attach
                            (When he wants to watch TV)
                              DeRegister/ DeAttach
                          (When he wants to not Watch TV)



           Observable                                       Observer

            2


                                      Notify
                           (When someone is Watching TV)

                                        3

            Observable                                      Observer




                                  Copyright 2006-2011
How Observer Pattern works in Java ?


                                                                            public void changeChannel(String channelName) {
    public static void main(String[] args) {                                  this.channelName = channelName;
       //Initialise Observable                                                setChanged();
       Television tv = new Television("Star Plus");                           this.notifyObservers();
                                                                            }
                                                              2
        //Initialise Observer
        TelevisionViewer tViewer = new TelevisionViewer();

         //Register Observer to Observable                                                      3
1       tv.addObserver(tViewer);

        //Change TV Channel
        tv.changeChannel("STAR CRICKET");
    }                                                                       public void update(Observable arg0, Object arg1) {
                                                                                         System.out.println("Channel Changed”);
                                                                            }




                                                      Copyright 2006-2011
THANK YOU


                   Please visit
www.eclipseinclips.com | www.ancitconsulting.com

     Write to us on info@ancitconsulting.com




                  QmPe
                  initiative


                   Copyright 2006-2011

More Related Content

PPSX
Observer design pattern
ODP
Design Pattern - 2. Observer
PPT
Observer Pattern Khali Young 2006 Aug
PPTX
Observer pattern
PDF
Observer Pattern
PPT
Observer and Decorator Pattern
PDF
Observer design pattern
PDF
Observer Pattern
Observer design pattern
Design Pattern - 2. Observer
Observer Pattern Khali Young 2006 Aug
Observer pattern
Observer Pattern
Observer and Decorator Pattern
Observer design pattern
Observer Pattern

What's hot (19)

PPTX
Design Pattern - Observer Pattern
PDF
Observer pattern
PPT
Observer pattern
PPT
Ext J S Observable
PPT
Ext Js Events
PPTX
Observer pattern
PPT
Iterator Design Pattern
PPTX
Scope.js prsentation
PDF
Data binding in AngularJS, from model to view
PPTX
Angular 2.0 change detection
PDF
How to build a react native app with the help of react native hooks
DOC
New Microsoft Word Document.doc
PPT
Wpf from David Kossoglyad
PPTX
Rxandroid
PPTX
DOCX
ECET 370 Exceptional Education - snaptutorial.com
PPTX
Android webinar class_3
DOCX
Scene manager
PDF
Art of unit testing: How developer should care about code quality
Design Pattern - Observer Pattern
Observer pattern
Observer pattern
Ext J S Observable
Ext Js Events
Observer pattern
Iterator Design Pattern
Scope.js prsentation
Data binding in AngularJS, from model to view
Angular 2.0 change detection
How to build a react native app with the help of react native hooks
New Microsoft Word Document.doc
Wpf from David Kossoglyad
Rxandroid
ECET 370 Exceptional Education - snaptutorial.com
Android webinar class_3
Scene manager
Art of unit testing: How developer should care about code quality
Ad

More from Annamalai Chockalingam (13)

PDF
Hello world e4 application part 5
PDF
Hello World e4 Application Part 7
PDF
Hello World e4 Application Part 6
PDF
Hello World e4 Application Part 2
PDF
Hello World e4 Application Part 3
PPT
Design patterns - Strategy Pattern
PPT
Design patterns - Factory Pattern
PPT
Design patterns - Decorator pattern
PPT
Design patterns - Adapter Pattern
PPT
Design patterns - Abstract Factory Pattern
PPT
Eclipse Spykit Project
PPT
Setting up Sphinx Development Environment
PPT
Eclipse Ecosystem in India
Hello world e4 application part 5
Hello World e4 Application Part 7
Hello World e4 Application Part 6
Hello World e4 Application Part 2
Hello World e4 Application Part 3
Design patterns - Strategy Pattern
Design patterns - Factory Pattern
Design patterns - Decorator pattern
Design patterns - Adapter Pattern
Design patterns - Abstract Factory Pattern
Eclipse Spykit Project
Setting up Sphinx Development Environment
Eclipse Ecosystem in India
Ad

Recently uploaded (20)

PDF
KodekX | Application Modernization Development
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPT
Teaching material agriculture food technology
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
cuic standard and advanced reporting.pdf
KodekX | Application Modernization Development
Building Integrated photovoltaic BIPV_UPV.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
MIND Revenue Release Quarter 2 2025 Press Release
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
MYSQL Presentation for SQL database connectivity
Review of recent advances in non-invasive hemoglobin estimation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Teaching material agriculture food technology
Network Security Unit 5.pdf for BCA BBA.
Dropbox Q2 2025 Financial Results & Investor Presentation
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
“AI and Expert System Decision Support & Business Intelligence Systems”
sap open course for s4hana steps from ECC to s4
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
cuic standard and advanced reporting.pdf

Design patterns - Observer Pattern

  • 1. QmPe initiative OBSERVER PATTERN explained ! Prepared by Annamalai C Copyright 2006-2011
  • 2. Observer Pattern in Real Life There is always a Observer and Observable object around you. You are an Observer, TV is an Observable Object. ----------------------------------- Ideology of Observer Pattern is something close. ----------------------------------- Colloquially Observers are called as Listeners Observables are called as Providers Observable Observer Copyright 2006-2011
  • 3. Observer Pattern in Java Observable Objects are called as Subject. Copyright 2006-2011
  • 4. Real Life vs Java Object Observer Copyright 2006-2011
  • 5. Real Life vs Java Object Observable Copyright 2006-2011
  • 6. How Observer Pattern works in Real Life ? 1 Register/ Attach (When he wants to watch TV) DeRegister/ DeAttach (When he wants to not Watch TV) Observable Observer 2 Notify (When someone is Watching TV) 3 Observable Observer Copyright 2006-2011
  • 7. How Observer Pattern works in Java ? public void changeChannel(String channelName) { public static void main(String[] args) { this.channelName = channelName; //Initialise Observable setChanged(); Television tv = new Television("Star Plus"); this.notifyObservers(); } 2 //Initialise Observer TelevisionViewer tViewer = new TelevisionViewer(); //Register Observer to Observable 3 1 tv.addObserver(tViewer); //Change TV Channel tv.changeChannel("STAR CRICKET"); } public void update(Observable arg0, Object arg1) { System.out.println("Channel Changed”); } Copyright 2006-2011
  • 8. THANK YOU Please visit www.eclipseinclips.com | www.ancitconsulting.com Write to us on info@ancitconsulting.com QmPe initiative Copyright 2006-2011