SlideShare ist ein Scribd-Unternehmen logo
1 von 8
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

Weitere ähnliche Inhalte

Was ist angesagt?

New Microsoft Word Document.doc
New Microsoft Word Document.docNew Microsoft Word Document.doc
New Microsoft Word Document.doc
butest
 
Android webinar class_3
Android webinar class_3Android webinar class_3
Android webinar class_3
Edureka!
 

Was ist angesagt? (19)

Design Pattern - Observer Pattern
Design Pattern - Observer PatternDesign Pattern - Observer Pattern
Design Pattern - Observer Pattern
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Ext J S Observable
Ext J S ObservableExt J S Observable
Ext J S Observable
 
Ext Js Events
Ext Js EventsExt Js Events
Ext Js Events
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design Pattern
 
Scope.js prsentation
Scope.js prsentationScope.js prsentation
Scope.js prsentation
 
Data binding in AngularJS, from model to view
Data binding in AngularJS, from model to viewData binding in AngularJS, from model to view
Data binding in AngularJS, from model to view
 
Angular 2.0 change detection
Angular 2.0 change detectionAngular 2.0 change detection
Angular 2.0 change detection
 
How to build a react native app with the help of react native hooks
How to build a react native app with the help of react native hooksHow to build a react native app with the help of react native hooks
How to build a react native app with the help of react native hooks
 
New Microsoft Word Document.doc
New Microsoft Word Document.docNew Microsoft Word Document.doc
New Microsoft Word Document.doc
 
Wpf from David Kossoglyad
Wpf from David KossoglyadWpf from David Kossoglyad
Wpf from David Kossoglyad
 
Rxandroid
RxandroidRxandroid
Rxandroid
 
Junit basics
Junit basicsJunit basics
Junit basics
 
ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com
 
Android webinar class_3
Android webinar class_3Android webinar class_3
Android webinar class_3
 
Scene manager
Scene managerScene manager
Scene manager
 
Art of unit testing: How developer should care about code quality
Art of unit testing: How developer should care about code qualityArt of unit testing: How developer should care about code quality
Art of unit testing: How developer should care about code quality
 

Mehr von Annamalai Chockalingam

Mehr von Annamalai Chockalingam (13)

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

Kürzlich hochgeladen

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 

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