Develop a program that utilizes the observer design pattern

Assignment Help Programming Languages
Reference no: EM131309230

Program

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: EM131309230

Questions Cloud

Write a letter to the business owner : Think about a negative customer service experience you had recently. Write a letter to the business owner or the company's customer service department explaining what happened.
Determine the reservation price : Analyze the bargaining situation and whether or not it is distributive. If so, determine the reservation price. Present the initial offer you would make and apply bracketing to achieve your target price of $310,000.
Explain the five phases of the project : Explain the five phases of the project. Provide a detailed description of each phase.Describe the key deliverables associated with each of the project options.Analyze each of the projects to determine which might be best to implement. Use such appr..
Define the term crm system : 1. List 5 objectives that transaction processing are expected to accomplish? 2. Define the term CRM system? List and define 5 key features of a CRM system? 3. Define the scope and goals of supply chain management.
Develop 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.
Find online reviews for a product you would like to buy : Find online reviews for a product you would like to buy. Which of the reviews infl uences you most? What about these reviews do you find persuasive?
Secure encrypted communications : Transmitting personal and business data and information over secure communication channels is critical. In some cases it is required, especially when personally identifiable information is being transmitted. Credit card numbers, Social Security Nu..
Write letter to business owner or companys customer service : Think about a negative customer service experience you had recently. Write a letter to the business owner or the company's customer service department explaining what happened.
Present an analysis of a change effort : After studying the various OD interventions and theories, present an analysis of a change effort that you experienced (that succeeded). Identify one presented theory or intervention that most closely relates to why the change effort succeeded. The..

Reviews

Write a Review

Programming Languages Questions & Answers

  Which one best describes the asymptotic class

Let f(n) = n (n + 1) / 2. Of the following possibilities, state which are true about f and of those, which one best describes the asymptotic class of f?

  Write a program to calculate diameter in centimeters

Write a program to compute the diameter in centimeters of steel rod, aluminum rod, adn copper rod, which can withstand a particular compression load.

  Program to compute percentage and final grade for students

Write a program which will permit teacher to compute percentage and final grade for students in a class.

  Draw a flow chart to outline how you want to solve

Those cards should be revealed for the remainder of the game - you are required to draw a flow chart to outline how you want to solve this problem.

  Calculate the adaptive wiener filter output at pixels

Calculate the adaptive Wiener filter output at pixels (2,2)and (3,3) using a 3x3 pixel neighborhood and uniform box filters. Discuss your findings.

  Describing program using suiatble printf command

Yyou have to describe all of this to user using suiatble printf() statements.

  Write css rule to gives all h elements padding

Write down CSS rule which gives all h1 and h2 elements padding of 0.5 ems, grooved border style and margin of 0.5ems. Prepare a layout template which contains header and two columns.

  Implement a query functionality to the catalogue

Implement a query functionality to the Catalogue. This will return a list of Albums that match a given criteria. We specify the criteria as a search rule (based on a very simple query language) that is executed against all the Genres and albums in..

  What are the benefits of the two when developing a compiler

What is the difference between top-down and bottom-up parsing

  Evaluates and prints the value of the polynomial

Write a program that evaluates and prints the value of the polynomial ax2 + bx + c, given user inputs for a, b, c, and x using integers and floats.

  Create a program that demonstrates the core algorithms

Create a program that demonstrates the core algorithms that will prototype the general operation of the application.

  A primitive data type that represents either true or false

A primitive data type that represents either true or false.

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