SlideShare a Scribd company logo
Class report




                   CLASS ASSIGNMENT- 2
                    OBSERVER PATTERN




         SHARE PRICE NOTIFICATION:



Introduction:
At first, we have to see what happens in this sort of share price notification
system, i.e. what features we have to focus on.

Now,let’s see the criteria that we have to maintain in our program. When a
user or client is registering ,he/she has to be added to the userlist. At the same
time, the preservation of the very information comes in mind.

But,if we think deeply, we can see that it’s not the responsibility of the user to
keep the registration information always in mind.Rather, the company is fully
responsible in respect of holding its users’ information.Now, the question
comes where will I keep the subscription info?So, let,s go through the whole
problem in brief.



There must be a Company class.Let’s, see what may be there…..




                                                                         Page 1 of 9
Class report

Company:
Company name:

Supportive information:

Userlist;

Shareprice:

So, some methods may be present like;

Registration();

ChangeShare();

NotifyUsers();



Again, there must be a User class.The features may be ….



User:
Name:

Description:

Functions like;

ReceiveNotification();

                         -may be present.



Another class named Share may be present. But, it’s not mandatory to take it
as a class .Rather, we can easily include it in the Company class.

Actually, what functions will play the key role can easily be detected.As,


                                                                        Page 2 of 9
Class report



Company                                           User

NotifyUser();                                     ReceiveNotification();




However;

           let’s focus, how we will troubleshoot the problem.

Company Class:
At first , we have to create a registration method in Company class in order to
maintain the generic registration issues.As for example;

Registration(User us){

Userlist.add(us);

}



Now, we have to maintain a suitable connection with the users who are added
to the userlist. If there is any change found in the share price then the
company has to notify the users about the possible change. As,

ChangeShare(double price){

If (shareprice !=price){

Shareprice=price;

NotifyUser();

}

}


                                                                      Page 3 of 9
Class report

NotifyUser(){

For all users in userlist{

//loop;

User.ReceiveNotification(shareprice,company name);

}}



User Class:
Now, after being called by NotifyUser() method, the ReceiveNotification()
method becomes active. So, it somehow sends the message that it has been
notifed. As,

ReceiveNotification(double price,company name){

Print(“I have been notified”);

}



So, what we clearly see here is that ,

                             Company notifies user.

                             User observe notification.

                             Hence, company – user observation process.

That’s why, this way of solving a problem is termed as “Observer Pattern”.

Now,

We have described the criteria in respect to one company only until now. If
we have to do the same thing in respect to many companies, then we just have
to add an abstract class namely AddCompany with some common features
extending the companies seperately with the extra features.

                                                                      Page 4 of 9
Class report




Likewise,




                           AddCompany



   Company1                  Company2                    ...............




Similarly,

We can use the same concept in case of multiple users,likewise;




                                                                           Page 5 of 9
Class report




                               AddUser



      User1                      User2                  .........




The main code to solve the problem is shown below:



Main Code:


User Class:


public class User {

      public static void main(String[ ] args) {

              Company cmp1 = new Company("Yahoo", 5000000);
              Company cmp2 = new Company("Apple", 4000000);

              ShareHolder sh1 = new ShareHolder("Mahedi", cmp1);
              cmp1.addShareHolder(sh1);
              ShareHolder sh2 = new ShareHolder("Mahfuj", cmp1);
              cmp1.addShareHolder(sh2);

                                                                    Page 6 of 9
Class report

            ShareHolder sh3 = new ShareHolder("Anik", cmp2);
            cmp2.addShareHolder(sh3);

            cmp1.changePrice(7000000);
            cmp2.changePrice(6000000);

      }
}




Company Class:

import java.util.ArrayList;

public class Company {

      private double sharePrice;
      private ArrayList<ShareHolder> sh;
      private String companyName;

      public Company(String cn,double sPrice){
            companyName = cn;
            sharePrice = sPrice;
            sh = new ArrayList<ShareHolder>();
      }

      public void addShareHolder(ShareHolder sh){
            this.sh.add(sh);
      }

                                                               Page 7 of 9
Class report

      public void changePrice(double sPrice){
            if(this.sharePrice != sPrice){
                   java.util.Iterator<ShareHolder> itr = sh.iterator();
                   while(itr.hasNext()){

      itr.next().receiveNotification(getCompanyName(),sPrice);
                   }
             }
      }

      public String getCompanyName() {
            return companyName;
      }

      }



Shareholder Class:
//This class is not mandatory.We can add the shareholder information in the
company class even.//

import java.util.ArrayList;

public class ShareHolder {

      private String holderName;
      private ArrayList<Company> regCom;

      public ShareHolder(String hn,Company cm){
            holderName = hn;
            regCom = new ArrayList<Company>();
      }

      public void registerTo(Company cm){
            this.regCom.add(cm);
      }


                                                                          Page 8 of 9
Class report

    public void receiveNotification(String cName,double sPrice){
          System.out.println(this.holderName + " is notified as sharePrice of
          " + cName + " is changed to " + sPrice);
    }

     }




……………………………………………………………………………..X…………………………………………………………………………………




                                                                    Page 9 of 9

More Related Content

Viewers also liked

Nmdl final pp 1
Nmdl final pp 1Nmdl final pp 1
Nmdl final pp 1kevinmsu
 
Understanding Your Credit Report
Understanding Your Credit ReportUnderstanding Your Credit Report
Understanding Your Credit Reportheatherviolet
 
Interviews 1
Interviews 1Interviews 1
Interviews 1Mayela TD
 
New microsoft office word 97 2003 document
New microsoft office word 97   2003 documentNew microsoft office word 97   2003 document
New microsoft office word 97 2003 document
Rajib Paul
 

Viewers also liked (12)

Map reduce
Map reduceMap reduce
Map reduce
 
Apache hadoop & map reduce
Apache hadoop & map reduceApache hadoop & map reduce
Apache hadoop & map reduce
 
R with excel
R with excelR with excel
R with excel
 
Nmdl final pp 1
Nmdl final pp 1Nmdl final pp 1
Nmdl final pp 1
 
Big data
Big dataBig data
Big data
 
Icons presentation
Icons presentationIcons presentation
Icons presentation
 
Understanding Your Credit Report
Understanding Your Credit ReportUnderstanding Your Credit Report
Understanding Your Credit Report
 
Interviews 1
Interviews 1Interviews 1
Interviews 1
 
New microsoft office word 97 2003 document
New microsoft office word 97   2003 documentNew microsoft office word 97   2003 document
New microsoft office word 97 2003 document
 
Strategy pattern.pdf
Strategy pattern.pdfStrategy pattern.pdf
Strategy pattern.pdf
 
Job search_resume
Job search_resumeJob search_resume
Job search_resume
 
Twitter
TwitterTwitter
Twitter
 

Similar to Observer pattern

srcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docx
srcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docxsrcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docx
srcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docx
rafbolet0
 
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docxLab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
smile790243
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
C++ Homework Help
 
Google Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification GoogleGoogle Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification Google
Mathias Seguy
 
1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org
AbbyWhyte974
 
1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org
MartineMccracken314
 
Java căn bản - Chapter4
Java căn bản - Chapter4Java căn bản - Chapter4
Java căn bản - Chapter4Vince Vo
 
Chapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part IChapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part I
Eduardo Bergavera
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
Mohammed Saleh
 
Diving into VS 2015 Day5
Diving into VS 2015 Day5Diving into VS 2015 Day5
Diving into VS 2015 Day5Akhil Mittal
 
Previous weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docxPrevious weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docx
keilenettie
 
Intake 38 5 1
Intake 38 5 1Intake 38 5 1
Intake 38 5 1
Mahmoud Ouf
 
Open microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletOpen microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutlet
Mitchinson
 
Pseudocode algorithim flowchart
Pseudocode algorithim flowchartPseudocode algorithim flowchart
Pseudocode algorithim flowchart
fika sweety
 
C sharp chap5
C sharp chap5C sharp chap5
C sharp chap5
Mukesh Tekwani
 
Diving into VS 2015 Day3
Diving into VS 2015 Day3Diving into VS 2015 Day3
Diving into VS 2015 Day3Akhil Mittal
 
CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces  CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces
HomeWork-Fox
 
Leverage StandardSetController in Apex and Visualforce
Leverage StandardSetController in Apex and VisualforceLeverage StandardSetController in Apex and Visualforce
Leverage StandardSetController in Apex and VisualforceSalesforce Developers
 

Similar to Observer pattern (20)

Observer pattern
Observer patternObserver pattern
Observer pattern
 
srcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docx
srcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docxsrcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docx
srcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docx
 
Eclipse Tricks
Eclipse TricksEclipse Tricks
Eclipse Tricks
 
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docxLab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Google Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification GoogleGoogle Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification Google
 
1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org
 
1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org1-What are the opportunities and threats that could impact the org
1-What are the opportunities and threats that could impact the org
 
Java căn bản - Chapter4
Java căn bản - Chapter4Java căn bản - Chapter4
Java căn bản - Chapter4
 
Chapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part IChapter 4 - Defining Your Own Classes - Part I
Chapter 4 - Defining Your Own Classes - Part I
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Diving into VS 2015 Day5
Diving into VS 2015 Day5Diving into VS 2015 Day5
Diving into VS 2015 Day5
 
Previous weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docxPrevious weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docx
 
Intake 38 5 1
Intake 38 5 1Intake 38 5 1
Intake 38 5 1
 
Open microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletOpen microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutlet
 
Pseudocode algorithim flowchart
Pseudocode algorithim flowchartPseudocode algorithim flowchart
Pseudocode algorithim flowchart
 
C sharp chap5
C sharp chap5C sharp chap5
C sharp chap5
 
Diving into VS 2015 Day3
Diving into VS 2015 Day3Diving into VS 2015 Day3
Diving into VS 2015 Day3
 
CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces  CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces
 
Leverage StandardSetController in Apex and Visualforce
Leverage StandardSetController in Apex and VisualforceLeverage StandardSetController in Apex and Visualforce
Leverage StandardSetController in Apex and Visualforce
 

More from Md. Mahedi Mahfuj

Advanced computer architecture
Advanced computer architectureAdvanced computer architecture
Advanced computer architectureMd. Mahedi Mahfuj
 
Database management system chapter16
Database management system chapter16Database management system chapter16
Database management system chapter16Md. Mahedi Mahfuj
 
Database management system chapter15
Database management system chapter15Database management system chapter15
Database management system chapter15Md. Mahedi Mahfuj
 
Database management system chapter12
Database management system chapter12Database management system chapter12
Database management system chapter12Md. Mahedi Mahfuj
 
Strategies in job search process
Strategies in job search processStrategies in job search process
Strategies in job search processMd. Mahedi Mahfuj
 
Basic and logical implementation of r language
Basic and logical implementation of r language Basic and logical implementation of r language
Basic and logical implementation of r language Md. Mahedi Mahfuj
 
Chatbot Artificial Intelligence
Chatbot Artificial IntelligenceChatbot Artificial Intelligence
Chatbot Artificial IntelligenceMd. Mahedi Mahfuj
 

More from Md. Mahedi Mahfuj (18)

Parallel computing(1)
Parallel computing(1)Parallel computing(1)
Parallel computing(1)
 
Message passing interface
Message passing interfaceMessage passing interface
Message passing interface
 
Advanced computer architecture
Advanced computer architectureAdvanced computer architecture
Advanced computer architecture
 
Matrix multiplication graph
Matrix multiplication graphMatrix multiplication graph
Matrix multiplication graph
 
Strategy pattern
Strategy patternStrategy pattern
Strategy pattern
 
Database management system chapter16
Database management system chapter16Database management system chapter16
Database management system chapter16
 
Database management system chapter15
Database management system chapter15Database management system chapter15
Database management system chapter15
 
Database management system chapter12
Database management system chapter12Database management system chapter12
Database management system chapter12
 
Strategies in job search process
Strategies in job search processStrategies in job search process
Strategies in job search process
 
Report writing(short)
Report writing(short)Report writing(short)
Report writing(short)
 
Report writing(long)
Report writing(long)Report writing(long)
Report writing(long)
 
Job search_interview
Job search_interviewJob search_interview
Job search_interview
 
Basic and logical implementation of r language
Basic and logical implementation of r language Basic and logical implementation of r language
Basic and logical implementation of r language
 
R language
R languageR language
R language
 
Chatbot Artificial Intelligence
Chatbot Artificial IntelligenceChatbot Artificial Intelligence
Chatbot Artificial Intelligence
 
Cloud testing v1
Cloud testing v1Cloud testing v1
Cloud testing v1
 
Distributed deadlock
Distributed deadlockDistributed deadlock
Distributed deadlock
 
Paper review
Paper review Paper review
Paper review
 

Recently uploaded

Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 

Recently uploaded (20)

Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 

Observer pattern

  • 1. Class report CLASS ASSIGNMENT- 2 OBSERVER PATTERN SHARE PRICE NOTIFICATION: Introduction: At first, we have to see what happens in this sort of share price notification system, i.e. what features we have to focus on. Now,let’s see the criteria that we have to maintain in our program. When a user or client is registering ,he/she has to be added to the userlist. At the same time, the preservation of the very information comes in mind. But,if we think deeply, we can see that it’s not the responsibility of the user to keep the registration information always in mind.Rather, the company is fully responsible in respect of holding its users’ information.Now, the question comes where will I keep the subscription info?So, let,s go through the whole problem in brief. There must be a Company class.Let’s, see what may be there….. Page 1 of 9
  • 2. Class report Company: Company name: Supportive information: Userlist; Shareprice: So, some methods may be present like; Registration(); ChangeShare(); NotifyUsers(); Again, there must be a User class.The features may be …. User: Name: Description: Functions like; ReceiveNotification(); -may be present. Another class named Share may be present. But, it’s not mandatory to take it as a class .Rather, we can easily include it in the Company class. Actually, what functions will play the key role can easily be detected.As, Page 2 of 9
  • 3. Class report Company User NotifyUser(); ReceiveNotification(); However; let’s focus, how we will troubleshoot the problem. Company Class: At first , we have to create a registration method in Company class in order to maintain the generic registration issues.As for example; Registration(User us){ Userlist.add(us); } Now, we have to maintain a suitable connection with the users who are added to the userlist. If there is any change found in the share price then the company has to notify the users about the possible change. As, ChangeShare(double price){ If (shareprice !=price){ Shareprice=price; NotifyUser(); } } Page 3 of 9
  • 4. Class report NotifyUser(){ For all users in userlist{ //loop; User.ReceiveNotification(shareprice,company name); }} User Class: Now, after being called by NotifyUser() method, the ReceiveNotification() method becomes active. So, it somehow sends the message that it has been notifed. As, ReceiveNotification(double price,company name){ Print(“I have been notified”); } So, what we clearly see here is that , Company notifies user. User observe notification. Hence, company – user observation process. That’s why, this way of solving a problem is termed as “Observer Pattern”. Now, We have described the criteria in respect to one company only until now. If we have to do the same thing in respect to many companies, then we just have to add an abstract class namely AddCompany with some common features extending the companies seperately with the extra features. Page 4 of 9
  • 5. Class report Likewise, AddCompany Company1 Company2 ............... Similarly, We can use the same concept in case of multiple users,likewise; Page 5 of 9
  • 6. Class report AddUser User1 User2 ......... The main code to solve the problem is shown below: Main Code: User Class: public class User { public static void main(String[ ] args) { Company cmp1 = new Company("Yahoo", 5000000); Company cmp2 = new Company("Apple", 4000000); ShareHolder sh1 = new ShareHolder("Mahedi", cmp1); cmp1.addShareHolder(sh1); ShareHolder sh2 = new ShareHolder("Mahfuj", cmp1); cmp1.addShareHolder(sh2); Page 6 of 9
  • 7. Class report ShareHolder sh3 = new ShareHolder("Anik", cmp2); cmp2.addShareHolder(sh3); cmp1.changePrice(7000000); cmp2.changePrice(6000000); } } Company Class: import java.util.ArrayList; public class Company { private double sharePrice; private ArrayList<ShareHolder> sh; private String companyName; public Company(String cn,double sPrice){ companyName = cn; sharePrice = sPrice; sh = new ArrayList<ShareHolder>(); } public void addShareHolder(ShareHolder sh){ this.sh.add(sh); } Page 7 of 9
  • 8. Class report public void changePrice(double sPrice){ if(this.sharePrice != sPrice){ java.util.Iterator<ShareHolder> itr = sh.iterator(); while(itr.hasNext()){ itr.next().receiveNotification(getCompanyName(),sPrice); } } } public String getCompanyName() { return companyName; } } Shareholder Class: //This class is not mandatory.We can add the shareholder information in the company class even.// import java.util.ArrayList; public class ShareHolder { private String holderName; private ArrayList<Company> regCom; public ShareHolder(String hn,Company cm){ holderName = hn; regCom = new ArrayList<Company>(); } public void registerTo(Company cm){ this.regCom.add(cm); } Page 8 of 9
  • 9. Class report public void receiveNotification(String cName,double sPrice){ System.out.println(this.holderName + " is notified as sharePrice of " + cName + " is changed to " + sPrice); } } ……………………………………………………………………………..X………………………………………………………………………………… Page 9 of 9