Resources

Example 11-1: A Switch to Control Which Driver to Use

TOC

Example 11-2: Using Polymorphism to Solve the Problem


Example 11-3: Implementation of ResFactory

TOC

Example 11-1: A Switch to Control Which Driver to Use


ApControl

TOP
ApControl.h
#pragma once

#typedef enum { LOW, HIGH } Resolution;

class ApControl
{
public:
	ApControl(void);
	void doDraw();
	void doPrint();
public:
	~ApControl(void);
private:
	Resolution myResolution;
};
ApControl.cpp
#include "ApControl.h"

ApControl::ApControl(void)
{
	// Set myResolution based on configuration
}

ApControl::~ApControl(void)
{
}

void ApControl::void doDraw()
{
    switch (myResolution) 
	{
        case LOW:
            // use lrdd
			break;
        case HIGH:
            // use hrdd
			break;
      }
}

void ApControl::doPrint()
{
    switch (myResolution) 
	{
        case LOW:
            // use lrpd
            break;
        case HIGH:
            // use hrpd
            break;
      }
}

Example 11-2: Using Polymorphism to Solve the Problem


Example 11-3: Implementation of ResFactory


ApControl

TOP
ApControl.h
#pragma once
#include "DisplayDriver.h"
#include "PrintDriver.h"
#include "ResFactory.h"

class ApControl
{
public:
	ApControl(void);
	void doPrint(void);
	void doDraw(void);
public:
	~ApControl(void);
private:
	ResFactory *myResFactory;
	DisplayDriver *myDisplayDriver;
	PrintDriver *myPrintDriver;
};
ApControl.cpp
#include "ApControl.h"

ApControl::ApControl(void)
{
	ResFactory *myResFactory= ResFactory::getFactory();
	myDisplayDriver= myResFactory->getDispDrvr();
	myPrintDriver= myResFactory->getPrtDrvr();
}

ApControl::~ApControl(void)
{
}

void ApControl::doDraw(void)
{
//	. . .
	myDisplayDriver->draw();
}

void ApControl::doPrint(void)
{
//	. . .
	myPrintDriver->print();
}

ResFactory

TOP
ResFactory.h
#pragma once
#include "DisplayDriver.h"
#include "PrintDriver.h"

class ResFactory
{
public:
	ResFactory(void);
	virtual DisplayDriver* getDispDrvr(void)=0;
	virtual PrintDriver* getPrtDrvr(void)=0;
	static ResFactory* getFactory(void);
public:
	~ResFactory(void);
};
ResFactory.cpp
#include "ResFactory.h"
#include "HighResFactory.h"
#include "LowResFactory.h"

ResFactory::ResFactory(void)
{
}

ResFactory::~ResFactory(void)
{
}

ResFactory* ResFactory::getFactory (void)
{
	// Logic to decide which resolution to use
	// If are to use High Resolution
	return new HighResFactory;
	// if are to use Low Resolution
	return new LowResFactory;
}

HighResFact

TOP
HighResFact.h
#pragma once
#include "resfactory.h"
#include "HRDD.h"
#include "HRPD.h"

class HighResFact : public ResFactory
{
public:
	HighResFact(void);
	DisplayDriver* getDispDrvr(void);
	PrintDriver* getPrtDrvr(void);
public:
	~HighResFact(void);
};
HighResFact.cpp
#include "HighResFact.h"

HighResFact::HighResFact(void)
{
}

HighResFact::~HighResFact(void)
{
}
DisplayDriver* HighResFact::getDispDrvr(void)
{
	return new HRDD;
}

PrintDriver* HighResFact::getPrtDrvr(void)
{
	return new HRPD;
}

LowResFact

TOP
LowResFact.h
#pragma once
#include "resfactory.h"
#include "LRDD.h"
#include "LRPD.h"

class LowResFact : 	public ResFactory
{
public:
	LowResFact(void);
	DisplayDriver* getDispDrvr(void);
	PrintDriver* getPrtDrvr(void);
public:
	~LowResFact(void);
};
LowResFact.cpp
#include "LowResFact.h"

LowResFact::LowResFact(void)
{
}

LowResFact::~LowResFact(void)
{
}

DisplayDriver* LowResFact::getDispDrvr(void)
{
	return new LRDD;
}

PrintDriver* LowResFact::getPrtDrvr(void)
{
	return new LRPD;
}

DisplayDriver

TOP
DisplayDriver.h
#pragma once

class DisplayDriver
{
public:
	DisplayDriver(void);
	virtual void draw(void)=0;
public:
	~DisplayDriver(void);
};
DisplayDriver.cpp
#include "DisplayDriver.h"

DisplayDriver::DisplayDriver(void)
{
}

DisplayDriver::~DisplayDriver(void)
{
}

HRDD

TOP
HRDD.h
#pragma once
#include "displaydriver.h"

class HRDD : public DisplayDriver
{
public:
	HRDD(void);
	void draw(void);
public:
	~HRDD(void);
};
HRDD.cpp
#include "HRDD.h"

HRDD::HRDD(void)
{
}

HRDD::~HRDD(void)
{
}

void HRDD::draw(void) 
{
	// do high resolution draw
}

LRDD

TOP
LRDD.h
#pragma once
#include "displaydriver.h"

class LRDD :
	public DisplayDriver
{
public:
	LRDD(void);
	void draw(void);
public:
	~LRDD(void);
};
LRDD.cpp
#include "LRDD.h"

LRDD::LRDD(void)
{
}

LRDD::~LRDD(void)
{
}

void LRDD::draw(void)
{
	// do low resolution draw
}

PrintDriver

TOP
PrintDriver.h
#pragma once

class PrintDriver
{
public:
	PrintDriver(void);
	virtual void print(void)=0;
public:
	~PrintDriver(void);
};
PrintDriver.cpp
#include "PrintDriver.h"

PrintDriver::PrintDriver(void)
{
}

PrintDriver::~PrintDriver(void)
{
}

HRPD

TOP
HRPD.h
#pragma once
#include "printdriver.h"

class HRPD : public PrintDriver
{
public:
	HRPD(void);
	void print(void);
public:
	~HRPD(void);
};
HRPD.cpp
#include "HRPD.h"

HRPD::HRPD(void)
{
}

HRPD::~HRPD(void)
{
}

void HRPD::print()
{
	// Do high resolution print
}

LRPD

TOP
LRPD.h
#pragma once
#include "printdriver.h"

class LRPD :
	public PrintDriver
{
public:
	LRPD(void);
	void print();
public:
	~LRPD(void);
};
LRPD.cpp
#include "LRPD.h"

LRPD::LRPD(void)
{
}

LRPD::~LRPD(void)
{
}

void LRPD::print()
{
	// do low resolution print
}
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