Resources

Example 18-1: Observer Implemented

TOC

Customer

TOP
Customer.h
#pragma once
#include 
#include 
#include "Observer.h"
using namespace std;

class Customer
{
public:
	Customer(void);
	
	void attach( Observer *myObserver);
	void detach( Observer *myObserver);
	string* getState();
	void notifyObs();
private:
	vector myObs;
public:
	~Customer(void);
};
Customer.cpp
#include "Customer.h"

Customer::Customer(void)
{
}

Customer::~Customer(void)
{
}

void Customer::attach( Observer *myObserver)
{
	myObs.push_back( myObserver);
}

void Customer::detach( Observer *myObserver)
{
	for (int i= 0; i< myObs.size(); i++)
	{
		if (myObs[i]== myObserver)
		{
			myObs.erase(myObs.begin()+i);
			return;
		}
	}
}

void Customer::notifyObs()
{
	// set arg to something that helps
	// tell the Observers what happened
	for (int i= 0; i< myObs.size(); i++)
	{
		myObs[i]->update(this);
	}
}

string* Customer::getState()
{
	string *state= new string;

	// set state

	return 0l;
}

Observer

TOP
Observer.h
#pragma once
class Customer;

class Observer
{
public:
	Observer(void);
	virtual void update( Customer *myCust)= 0;
public:
	~Observer(void);
};
Observer.cpp
#include "Observer.h"

Observer::Observer(void)
{
}

Observer::~Observer(void)
{
}

AddrVerification

TOP
AddrVerification.h
#pragma once
#include "Observer.h"
#include "Customer.h"

class AddrVerification : public Observer
{
public:
	AddrVerification(void);
	void update( Customer *myCust);
public:
	~AddrVerification(void);
};
AddrVerification.cpp
#include "AddrVerification.h"

AddrVerification::AddrVerification(void)
{
}

AddrVerification::~AddrVerification(void)
{
}

void AddrVerification::update ( Customer *myCust) 
{
      // do Address verification stuff here
      // can get more information about customer
      // in question by using myCust
}

WelcomeLetter

TOP
WelcomeLetter.h
#pragma once
#include "Observer.h"
#include "Customer.h"

class WelcomeLetter : public Observer
{
public:
	WelcomeLetter(void);
	void update( Customer *myCust);
public:
	~WelcomeLetter(void);
};
WelcomeLetter.cpp
#include "WelcomeLetter.h"

WelcomeLetter::WelcomeLetter(void)
{
}

WelcomeLetter::~WelcomeLetter(void)
{
}

void WelcomeLetter::update( Customer *myCust)
{
   // do Welcome Letter stuff 
   // here can get more 
   // information about customer 
   // in question by using myCust
}
Sample Podcast

Lean and What do we do next? - Part 2
Presenter's photo January 25th, 2007
Author: Jim Trott

These Lean-Agile principles all seem reasonable, but abstract. What do we do to put it into practice? This is part 2 of a discussion on this.

Free Registration Gets You More!

Register for a free Net Objectives account, and you'll gain access to much more content: more Streamzines, more Ezines, our bibliographies and FAQ's, and all the preparatory material we recommend to anyone planning to take a Net Objectives course.

Why Register? Register Now