SlideShare a Scribd company logo
1 of 24
2
3
 Name: Singleton
 Intent: Ensure a class has only one instance and
provide a global point of access to it
 Problem: How can we guarantee that one and only one
instance of a class can be created?
 Solution: Define a class with a private constructor.
The class constructs a single instance of itself
Supply a static method that returns a reference to
the single instance.
4
5
6
 A status bar ….It could be implemented as a Singleton
object, allowing only one instance and a focal point for
updates.
 One file system, one window manager, one printer
spooler, one Test engine, one Input/Output socket ,
Windows Registry etc.
7
Class Singleton {
private static Singleton uniqueInstance = null;
private Singleton( ) { .. } // private constructor
public static Singleton getInstance( ) {
if (uniqueInstance == null)
uniqueInstance = new Singleton();
// call constructor
return uniqueInstance;
}
}
Singleton: Basic Implementation
8
 We want to create a remote connection to a
server / database system and assure that only one
connection is present.
 Apply Singleton pattern
9
Class RemoteConnection{
private static RemoteConnetion remoteConn;
private RemoteConnection(){…} //private Constructor
public static RemoteConnection getInstance(){
if(remoteConn == null){
remoteConn = new RemoteConnection();
}
return remoteConn;
}
}
In a university….when a student changes his
address…pass this information to:
Exams department
transport department
What's the solution?
10
11
Different Objects
Different Interfaces
Observers
Observable
12
 Name: Observer
 Intent: Define a one-to-many dependency between
objects so that when one object changes state, all its
dependents are notified and updated automatically.
 Problem: You need to notify a varying list of objects
that an event has occurred.
 Solution: delegate the responsibility for monitoring an
event to a central object.
13
 Step 1: Make the Observers behave in the same way
 Step 2: Have the observers register themselves
 Step 3: Notify the observers when the event occurs
 Step 4: Get the information from the observable
14
15
16
public interface myObserver{
public void update(Student s);
}
17
class ExamDept implements myObserver{
public void update(Student s){
System.out.println("Student Updated in Exam Dept");
System.out.println("New Address: "+ s.getAddress());
}
}
18
class TransportDept implements myObserver{
public void update(Student s){
System.out.println("Student Updated in TD");
System.out.println("New Address:
"+s.getAddress());
}
}
19
class Student{
private String address;
private Vector myObs;
public Student(){ myObs = new Vector(); address = "Rawalpindi"; }
public void register(myObserver obs){ myObs.addElement(obs); }
public void unRegister(myObserver obs){ myObs.remove(obs); }
public void notifyObs(){
Enumeration e = myObs.elements();
while(e.hasMoreElements()){
((myObserver)e.nextElement()).update(this); } }
public void changeAddress(){ address = "Islamabad"; notifyObs(); }
}
20
class Main{
public static void main(String[]args){
Student s = new Student();
TransportDept td = new TransportDept();
ExamDept ed = new ExamDept();
System.out.println("Present Address:" + s.getAddress());
s.register(td);
s.register(ed);
s.changeAddress();
System.out.println("******Unregister Exam Dept*******");
s.unRegister(ed);
s.changeAddress();
}
}
21
22
Suppose you are working on an MDI (Multiple
Documents Interface) Form that has several child.
You need to notify all the child about the changes
that occur in MDI form (e.g title changed).
Apply Observer pattern to solve this problem and
draw the corresponding class diagram.
23
24

More Related Content

What's hot

Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
Sara Torkey
 
962 sech04
962 sech04962 sech04
962 sech04
aldwal
 
class and objects
class and objectsclass and objects
class and objects
Payel Guria
 
.NET Framework Overview
.NET Framework Overview.NET Framework Overview
.NET Framework Overview
Doncho Minkov
 

What's hot (20)

Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
 
Packages,interfaces and exceptions
Packages,interfaces and exceptionsPackages,interfaces and exceptions
Packages,interfaces and exceptions
 
Ch18 service oriented software engineering
Ch18 service oriented software engineeringCh18 service oriented software engineering
Ch18 service oriented software engineering
 
Abstraction and Encapsulation
Abstraction and EncapsulationAbstraction and Encapsulation
Abstraction and Encapsulation
 
962 sech04
962 sech04962 sech04
962 sech04
 
Activity diagram
Activity diagramActivity diagram
Activity diagram
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singh
 
Event handling
Event handlingEvent handling
Event handling
 
Inheritance
InheritanceInheritance
Inheritance
 
Unit 2-Design Patterns.ppt
Unit 2-Design Patterns.pptUnit 2-Design Patterns.ppt
Unit 2-Design Patterns.ppt
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Debugging in visual studio (basic level)
Debugging in visual studio (basic level)Debugging in visual studio (basic level)
Debugging in visual studio (basic level)
 
class and objects
class and objectsclass and objects
class and objects
 
.NET Framework Overview
.NET Framework Overview.NET Framework Overview
.NET Framework Overview
 
Observer Software Design Pattern
Observer Software Design Pattern Observer Software Design Pattern
Observer Software Design Pattern
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
 
principles of object oriented class design
principles of object oriented class designprinciples of object oriented class design
principles of object oriented class design
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design Pattern
 
Basic Behavioral Modeling
Basic Behavioral ModelingBasic Behavioral Modeling
Basic Behavioral Modeling
 

Viewers also liked

Observer pattern, delegate, event, lambda expression
Observer pattern, delegate, event, lambda expressionObserver pattern, delegate, event, lambda expression
Observer pattern, delegate, event, lambda expression
LearningTech
 
Design patterns
Design patternsDesign patterns
Design patterns
ISsoft
 
Observer Pattern Khali Young 2006 Aug
Observer Pattern Khali Young 2006 AugObserver Pattern Khali Young 2006 Aug
Observer Pattern Khali Young 2006 Aug
melbournepatterns
 
Design patterns 4 - observer pattern
Design patterns   4 - observer patternDesign patterns   4 - observer pattern
Design patterns 4 - observer pattern
pixelblend
 

Viewers also liked (20)

Singleton pattern
Singleton patternSingleton pattern
Singleton pattern
 
Design Pattern - 2. Observer
Design Pattern -  2. ObserverDesign Pattern -  2. Observer
Design Pattern - 2. Observer
 
Observer pattern, delegate, event, lambda expression
Observer pattern, delegate, event, lambda expressionObserver pattern, delegate, event, lambda expression
Observer pattern, delegate, event, lambda expression
 
Design patterns
Design patternsDesign patterns
Design patterns
 
The Observer Pattern (Definition using UML)
The Observer Pattern (Definition using UML)The Observer Pattern (Definition using UML)
The Observer Pattern (Definition using UML)
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Design patterns: observer pattern
Design patterns: observer patternDesign patterns: observer pattern
Design patterns: observer pattern
 
Observer Pattern Khali Young 2006 Aug
Observer Pattern Khali Young 2006 AugObserver Pattern Khali Young 2006 Aug
Observer Pattern Khali Young 2006 Aug
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Design patterns 4 - observer pattern
Design patterns   4 - observer patternDesign patterns   4 - observer pattern
Design patterns 4 - observer pattern
 
Factory Pattern
Factory PatternFactory Pattern
Factory Pattern
 
Design Patterns in Cocoa Touch
Design Patterns in Cocoa TouchDesign Patterns in Cocoa Touch
Design Patterns in Cocoa Touch
 
Reflective portfolio
Reflective portfolioReflective portfolio
Reflective portfolio
 
Design patterns - Observer Pattern
Design patterns - Observer PatternDesign patterns - Observer Pattern
Design patterns - Observer Pattern
 
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
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
 
Design pattern - Software Engineering
Design pattern - Software EngineeringDesign pattern - Software Engineering
Design pattern - Software Engineering
 

Similar to Observer & singleton pattern

Factory method, strategy pattern & chain of responsibilities
Factory method, strategy pattern & chain of responsibilitiesFactory method, strategy pattern & chain of responsibilities
Factory method, strategy pattern & chain of responsibilities
babak danyal
 
Core Java- An advanced review of features
Core Java- An advanced review of featuresCore Java- An advanced review of features
Core Java- An advanced review of features
vidyamittal
 
Advance java kvr -satya
Advance java  kvr -satyaAdvance java  kvr -satya
Advance java kvr -satya
Satya Johnny
 
Factory method & strategy pattern
Factory method & strategy patternFactory method & strategy pattern
Factory method & strategy pattern
babak danyal
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
LearningTech
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
LearningTech
 
Building a Driver: Lessons Learned From Developing the Internet Explorer Driver
Building a Driver: Lessons Learned From Developing the Internet Explorer DriverBuilding a Driver: Lessons Learned From Developing the Internet Explorer Driver
Building a Driver: Lessons Learned From Developing the Internet Explorer Driver
seleniumconf
 

Similar to Observer & singleton pattern (20)

Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 
04 threads
04 threads04 threads
04 threads
 
Factory method, strategy pattern & chain of responsibilities
Factory method, strategy pattern & chain of responsibilitiesFactory method, strategy pattern & chain of responsibilities
Factory method, strategy pattern & chain of responsibilities
 
C# Unit 2 notes
C# Unit 2 notesC# Unit 2 notes
C# Unit 2 notes
 
Taming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, MacoscopeTaming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, Macoscope
 
Advanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAdvanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sir
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Design patterns in Java - Monitis 2017
Design patterns in Java - Monitis 2017Design patterns in Java - Monitis 2017
Design patterns in Java - Monitis 2017
 
Core Java- An advanced review of features
Core Java- An advanced review of featuresCore Java- An advanced review of features
Core Java- An advanced review of features
 
Adv kvr -satya
Adv  kvr -satyaAdv  kvr -satya
Adv kvr -satya
 
Advance java kvr -satya
Advance java  kvr -satyaAdvance java  kvr -satya
Advance java kvr -satya
 
Factory method & strategy pattern
Factory method & strategy patternFactory method & strategy pattern
Factory method & strategy pattern
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3
 
Spring andspringboot training
Spring andspringboot trainingSpring andspringboot training
Spring andspringboot training
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
 
Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805Design pattern proxy介紹 20130805
Design pattern proxy介紹 20130805
 
Building a Driver: Lessons Learned From Developing the Internet Explorer Driver
Building a Driver: Lessons Learned From Developing the Internet Explorer DriverBuilding a Driver: Lessons Learned From Developing the Internet Explorer Driver
Building a Driver: Lessons Learned From Developing the Internet Explorer Driver
 
Intake 37 4
Intake 37 4Intake 37 4
Intake 37 4
 
Android Unit Test
Android Unit TestAndroid Unit Test
Android Unit Test
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 

More from babak danyal

Lecture1 Intro To Signa
Lecture1 Intro To SignaLecture1 Intro To Signa
Lecture1 Intro To Signa
babak danyal
 

More from babak danyal (20)

applist
applistapplist
applist
 
Easy Steps to implement UDP Server and Client Sockets
Easy Steps to implement UDP Server and Client SocketsEasy Steps to implement UDP Server and Client Sockets
Easy Steps to implement UDP Server and Client Sockets
 
Java IO Package and Streams
Java IO Package and StreamsJava IO Package and Streams
Java IO Package and Streams
 
Swing and Graphical User Interface in Java
Swing and Graphical User Interface in JavaSwing and Graphical User Interface in Java
Swing and Graphical User Interface in Java
 
Tcp sockets
Tcp socketsTcp sockets
Tcp sockets
 
block ciphers and the des
block ciphers and the desblock ciphers and the des
block ciphers and the des
 
key distribution in network security
key distribution in network securitykey distribution in network security
key distribution in network security
 
Lecture10 Signal and Systems
Lecture10 Signal and SystemsLecture10 Signal and Systems
Lecture10 Signal and Systems
 
Lecture8 Signal and Systems
Lecture8 Signal and SystemsLecture8 Signal and Systems
Lecture8 Signal and Systems
 
Lecture7 Signal and Systems
Lecture7 Signal and SystemsLecture7 Signal and Systems
Lecture7 Signal and Systems
 
Lecture6 Signal and Systems
Lecture6 Signal and SystemsLecture6 Signal and Systems
Lecture6 Signal and Systems
 
Lecture5 Signal and Systems
Lecture5 Signal and SystemsLecture5 Signal and Systems
Lecture5 Signal and Systems
 
Lecture4 Signal and Systems
Lecture4  Signal and SystemsLecture4  Signal and Systems
Lecture4 Signal and Systems
 
Lecture3 Signal and Systems
Lecture3 Signal and SystemsLecture3 Signal and Systems
Lecture3 Signal and Systems
 
Lecture2 Signal and Systems
Lecture2 Signal and SystemsLecture2 Signal and Systems
Lecture2 Signal and Systems
 
Lecture1 Intro To Signa
Lecture1 Intro To SignaLecture1 Intro To Signa
Lecture1 Intro To Signa
 
Lecture9 Signal and Systems
Lecture9 Signal and SystemsLecture9 Signal and Systems
Lecture9 Signal and Systems
 
Lecture9
Lecture9Lecture9
Lecture9
 
Cns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption TechniquesCns 13f-lec03- Classical Encryption Techniques
Cns 13f-lec03- Classical Encryption Techniques
 
Classical Encryption Techniques in Network Security
Classical Encryption Techniques in Network SecurityClassical Encryption Techniques in Network Security
Classical Encryption Techniques in Network Security
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 

Observer & singleton pattern

  • 1.
  • 2. 2
  • 3. 3  Name: Singleton  Intent: Ensure a class has only one instance and provide a global point of access to it  Problem: How can we guarantee that one and only one instance of a class can be created?  Solution: Define a class with a private constructor. The class constructs a single instance of itself Supply a static method that returns a reference to the single instance.
  • 4. 4
  • 5. 5
  • 6. 6  A status bar ….It could be implemented as a Singleton object, allowing only one instance and a focal point for updates.  One file system, one window manager, one printer spooler, one Test engine, one Input/Output socket , Windows Registry etc.
  • 7. 7 Class Singleton { private static Singleton uniqueInstance = null; private Singleton( ) { .. } // private constructor public static Singleton getInstance( ) { if (uniqueInstance == null) uniqueInstance = new Singleton(); // call constructor return uniqueInstance; } } Singleton: Basic Implementation
  • 8. 8  We want to create a remote connection to a server / database system and assure that only one connection is present.  Apply Singleton pattern
  • 9. 9 Class RemoteConnection{ private static RemoteConnetion remoteConn; private RemoteConnection(){…} //private Constructor public static RemoteConnection getInstance(){ if(remoteConn == null){ remoteConn = new RemoteConnection(); } return remoteConn; } }
  • 10. In a university….when a student changes his address…pass this information to: Exams department transport department What's the solution? 10
  • 12. 12
  • 13.  Name: Observer  Intent: Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.  Problem: You need to notify a varying list of objects that an event has occurred.  Solution: delegate the responsibility for monitoring an event to a central object. 13
  • 14.  Step 1: Make the Observers behave in the same way  Step 2: Have the observers register themselves  Step 3: Notify the observers when the event occurs  Step 4: Get the information from the observable 14
  • 15. 15
  • 16. 16
  • 17. public interface myObserver{ public void update(Student s); } 17
  • 18. class ExamDept implements myObserver{ public void update(Student s){ System.out.println("Student Updated in Exam Dept"); System.out.println("New Address: "+ s.getAddress()); } } 18
  • 19. class TransportDept implements myObserver{ public void update(Student s){ System.out.println("Student Updated in TD"); System.out.println("New Address: "+s.getAddress()); } } 19
  • 20. class Student{ private String address; private Vector myObs; public Student(){ myObs = new Vector(); address = "Rawalpindi"; } public void register(myObserver obs){ myObs.addElement(obs); } public void unRegister(myObserver obs){ myObs.remove(obs); } public void notifyObs(){ Enumeration e = myObs.elements(); while(e.hasMoreElements()){ ((myObserver)e.nextElement()).update(this); } } public void changeAddress(){ address = "Islamabad"; notifyObs(); } } 20
  • 21. class Main{ public static void main(String[]args){ Student s = new Student(); TransportDept td = new TransportDept(); ExamDept ed = new ExamDept(); System.out.println("Present Address:" + s.getAddress()); s.register(td); s.register(ed); s.changeAddress(); System.out.println("******Unregister Exam Dept*******"); s.unRegister(ed); s.changeAddress(); } } 21
  • 22. 22
  • 23. Suppose you are working on an MDI (Multiple Documents Interface) Form that has several child. You need to notify all the child about the changes that occur in MDI form (e.g title changed). Apply Observer pattern to solve this problem and draw the corresponding class diagram. 23
  • 24. 24