All pastes #1585979 Raw Edit

Untitled

public text v1 · immutable
#1585979 ·published 2009-09-30 13:43 UTC
rendered paste body
Gee.HashMap<string,Command> commands;

public class Command : GLib.Object
{
	public Command()
	{
		message( "construct" );
	}
	~Command()
	{
		message( "destruct" );
		assert_not_reached();
	}
}

public Command factory( string name )
{
	Command? cmd = commands[name];
	assert( cmd != null );
	return cmd;
}

void create()
{
	commands = new Gee.HashMap<string,Command>();
	commands["+FOO"] = new Command();
}

void main()
{
	create();
	Command cmd = factory( "+FOO" ) as Command;
	cmd = null;
	Command cmd2 = factory( "+FOO" ) as Command;
	cmd2 = null;
}