Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 10 Weeks Ago, 6 Days Ago |
Questions Answered: | 4870 |
Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Please include comments in source filesÂ
Program #6
Due: Thursday Dec 1st, 2016 at 11:30PM
Purpose
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>
Â
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 include your source files.
Â
Â
Â
CS 1337.502,504 F16Program #6Page1of2Program #6Due: Thursday Dec 1st, 2016 at 11:30PMInstructorDr. Stephen PerkinsOffice LocationECSS 4.702Office Phone(972) 883-3891Email Addressstephen.perkins@utdallas.eduOffice HoursTuesday and Thursday 10:30am – 11:30amTuesday and Thursday 1:00pm – 2:15pmand by appointmentGraderSection 502:Sai Vamsi Muvvasxm154231@utdallas.eduOpen Lab 2.103B1Section 504:Gopichand Vankagxv151030@utdallas.eduOpen Lab 2.104A1Tuesday/Thursday 3:00pm – 5:00pmPurposeDemonstrate the ability to create a program that utilizes theObserverdesign pattern. Demonstratethe ability to create abstract classes and implement derived classes. Demonstrate the ability tocreate and iterate over anSTL listthat contains callback functions.AssignmentYou will be creating a program that implements theObserverdesign pattern.This design patternis utilized in almost all GUI systems and is the basis for distributed event handling.The goal ofthe 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 hasadditional member functions that allow other classes (the observers) to register and deregisterthemselves with the Subject. If observers are registered with the subject, they will receivenotifications (via a callback function) if the subject’s address ever changes.You are to create these observer classes BankObserver, SchoolObserver, CreditObserver.Eachof the observers must be derived from this abstract base class:classAbstractObserver{public:virtual voidsubjectChanged(string)=0;virtual~AbstractObserver(){}};Each should override thesubjectChangedmethod by printing the string argument to the screenalong with the name of it's class.For instance, the BankObserver might print the following:The BankObserver received an address change notification: <string>
Attachments: