Your SlideShare is downloading. ×
Design patterns - Observer Pattern
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Design patterns - Observer Pattern

913
views

Published on

Published in: Technology, Business

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
913
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
25
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. QmPe initiativeOBSERVER PATTERN explained ! Prepared by Annamalai C Copyright 2006-2011
  • 2. Observer Pattern in Real LifeThere 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 JavaObservable 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 31 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 visitwww.eclipseinclips.com | www.ancitconsulting.com Write to us on info@ancitconsulting.com QmPe initiative Copyright 2006-2011