Create a program that utilizes the observer design pattern

Assignment Help Other Subject
Reference no: EM131302651

Assignment

Demonstrate the ability to create a program that utilizes the Observer design pattern. Demonstrate the ability to create abstract classes and implement derived classes. Demonstrate the ability to create and iterate over an STL list that contains callback functions. Assignment You will be creating a program that implements the Observer design pattern. This design pattern is utilized in almost all GUI systems and is the basis for distributed event handling. The goal of the program is to create a class (the Subject class for this assignment) that has a private variable (address) that can be modified via a standard mutator function (setAddress). This class has additional member functions that allow other classes (the observers) to register and deregister themselves with the Subject. If observers are registered with the subject, they will receive notifications (via a callback function) if the subject's address ever changes.

You are to create these observer classes BankObserver, SchoolObserver, CreditObserver. Each of the observers must be derived from this abstract base class: class AbstractObserver { public: virtual void subjectChanged(string)=0; virtual ~AbstractObserver(){} }; Each should override the subjectChanged method by printing the string argument to the screen along with the name of it's class. For instance, the BankObserver might print the following:

The BankObserver received an address change notification: <string> CS 1337.502,504 F16 Program #6 Page 1 of 2 You will then create one instance of the Subject class and one instance each of three derived observer classes. You will register the instances of the observer classes with the instance of the Subject class. When registered, you will make a change to the instance of the subject class (using the setAddress method). This change should cause each of the registered observers to receive a callback with notification of the change. The notify() method implements this functionality.

You must then deregister at least one of the observer instances and make a change to the subject instance. This will result in only the remaining registered observers receiving notification.

Here is the Class prototype for the Subject:

class Subject { private: string address; list<AbstractObserver *> observers; void notify(); public: Subject(string addr); void addObserver(AbstractObserver& observer); void removeObserver(AbstractObserver& observer); string getAddress(); void setAddress(string newAddress); }; Requirements Your code must extend and use the AbstractObserver class

Your code must implement the Subject class

Your code must exhibit the use of the Observer design pattern

Your code must exhibit the use of the STL list data type

Your code must exhibit the use of an STL list iterator

Your code must exhibit correct operation with registered callbacks

Your code must exhibit correct operation with deregistered callbacks Deliverables

You must submit your homework through ELearning. You must include your source files.

No late homework is accepted. Observer Pattern (https://en.wikipedia.org/wiki/Observer_pattern)

The observer pattern is a software design pattern in which an object, called the subject,

maintains a list of its dependents, called observers, and notifies them automatically of any state

changes, usually by calling one of their methods. It is mainly used to implement distributed event

handling systems. The Observer pattern is also a key part in the familiar Model View Controller

(MVC) architectural pattern. [1] In fact the observer pattern was first implemented in Smalltalk's

MVC based user interface framework.[2] The observer pattern is implemented in numerous programming libraries and systems, including almost all GUI toolkits.

Reference no: EM131302651

Questions Cloud

Find the price of a call option on the stock : The current price of a stock is $21. In 1 year, the price will be either $27 or $15. The annual risk-free rate is 6%. Find the price of a call option on the stock that has a strike price is of $25 and that expires in 1 year.
Do you support or oppose the death penalty : Do you support or oppose the death penalty.Please make sure it is in third person and I support the death penalty.
Why the federal reserve need reasonably accurate forecasts : Why does the Federal Reserve need reasonably accurate forecasts of the economy to pursue and achieve successful monetary policy?
Delivery of governmental services : In 300 words. Public administration cannot exist outside of its political context. Discuss how politics affects the policymaking process and the delivery of governmental services.
Create a program that utilizes the observer design pattern : Demonstrate the ability to create a program that utilizes the Observer design pattern. Demonstrate the ability to create abstract classes and implement derived classes.
What is the interest rate channel : What do economists mean by the channels of monetary policy?- What is the interest rate channel?- What is the bank lending channel?
Developing financial planners at amp : Question What out comes should AMP collect to determine the effectiveness of the Career Changer Program? What evaluation design should it use? Explain your choice of out comes and design.
What is goodyears unlevered cost of capital : Suppose Goodyear Tire and Rubber Company has an equity cost of capital of 8.5%, a debt cost of capital of 7%, a marginal corporate tax rate of 35%, and a debt-equity ratio of 2.6. Suppose Goodyear maintains a constant debt-equity ratio. a. What is Go..
Cost controls in health care reimbursement models : Search the Internet for two articles about the methods of cost controls in health care reimbursement models and how the methods have affected the availability of services. Using the articles as resources, write at least two pages, addressing the f..

Reviews

Write a Review

Other Subject Questions & Answers

  Cross-cultural opportunities and conflicts in canada

Short Paper on Cross-cultural Opportunities and Conflicts in Canada.

  Sociology theory questions

Sociology are very fundamental in nature. Role strain and role constraint speak about the duties and responsibilities of the roles of people in society or in a group. A short theory about Darwin and Moths is also answered.

  A book review on unfaithful angels

This review will help the reader understand the social work profession through different concepts giving the glimpse of why the social work profession might have drifted away from its original purpose of serving the poor.

  Disorder paper: schizophrenia

Schizophrenia does not really have just one single cause. It is a possibility that this disorder could be inherited but not all doctors are sure.

  Individual assignment: two models handout and rubric

Individual Assignment : Two Models Handout and Rubric,    This paper will allow you to understand and evaluate two vastly different organizational models and to effectively communicate their differences.

  Developing strategic intent for toyota

The following report includes the description about the organization, its strategies, industry analysis in which it operates and its position in the industry.

  Gasoline powered passenger vehicles

In this study, we examine how gasoline price volatility and income of the consumers impacts consumer's demand for gasoline.

  An aspect of poverty in canada

Economics thesis undergrad 4th year paper to write. it should be about 22 pages in length, literature review, economic analysis and then data or cost benefit analysis.

  Ngn customer satisfaction qos indicator for 3g services

The paper aims to highlight the global trends in countries and regions where 3G has already been introduced and propose an implementation plan to the telecom operators of developing countries.

  Prepare a power point presentation

Prepare the power point presentation for the case: Santa Fe Independent School District

  Information literacy is important in this environment

Information literacy is critically important in this contemporary environment

  Associative property of multiplication

Write a definition for associative property of multiplication.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd