C++ XML Objects Use: Simple Design

Next Usage Home Installation Docs

Abstract

Let's start out with a simple class hierarchy.

Description

Our simple class hierarchy would be declared like this:

class root
{
private:
	int x;
	vector<foo *> foos;
	vector<bar *> bars;
	foo *a_foo;
	
public:
	root() : x(0), a_foo(0) {};
	~root()
	{
		for (vector<foo *>::iterator i=foos.begin(); i != foos.end(); i++)
			delete *i;
		for (vector<bar *>::iterator i=bars.begin(); i != bars.end(); i++)
			delete *i;
		if (a_foo)
			delete a_foo;
	}
};

class foo
{
private:
	int x;
	double y;
	bool z;
	
	public:
	foo() : x(0), y(0), z(0) {};
	virtual ~foo() {};
};

class bar : public foo
{
private:
	int a;
	double b;
	int c;
	
	public:
	bar() : a(0), b(0), c(0) {};
	virtual ~bar() {};
};

Forget about things like correct includes for STL, namespaces etc. They can all be used but make it look more complicated. The general idea is that we have a "bar" which is derived from "foo", and we have a "root" object which has lists of foos and bars, and a single pointer to a foo.

Next Usage Home Installation Docs


Generated: Wed Apr 5 23:00:19 EST 2006

Copyright (c) 2005; Paul Hamilton; pHamtec P/L.

Use, modification, and distribution is provided free of any limitations.