SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Design Pattern - Observer Pattern
Design Pattern - Observer PatternDesign Pattern - Observer Pattern
Design Pattern - Observer PatternMudasir Qazi
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design PatternVarun Arora
 
Scope.js prsentation
Scope.js prsentationScope.js prsentation
Scope.js prsentationAtishay Baid
 
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 viewThomas Roch
 
Angular 2.0 change detection
Angular 2.0 change detectionAngular 2.0 change detection
Angular 2.0 change detectionRan Wahle
 
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 hooksKaty Slemon
 
New Microsoft Word Document.doc
New Microsoft Word Document.docNew Microsoft Word Document.doc
New Microsoft Word Document.docbutest
 
ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com donaldzs157
 
Android webinar class_3
Android webinar class_3Android webinar class_3
Android webinar class_3Edureka!
 
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 qualityDmytro Patserkovskyi
 

Tendances (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
 

Plus de Annamalai Chockalingam

Plus de 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
 

Dernier

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Dernier (20)

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 

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