Skip to content

Mit Licence of TFactory template, my Factory DesignPattern without first instantiation

License

Notifications You must be signed in to change notification settings

Jaders77/designpattern-factory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Design Pattern Factory

Factory Design Pattern without first instantiation.

Most implementations of Factory require an instance for future use of the copy operator. This version uses only the type of the object and the default operator.

The goals of TFactory are:

  • Mit Licence (see LICENSE)
  • Zero dependencies (only STD)
  • Only one file
  • Portable
  • Easy to use

Simple sample of usage:

class Object
{
public:
	Object(void) {};
	virtual ~Object(void) {};
};

class MyObject1 : public Object
{
public:
	MyObject1(void) {};
};

class MyObject2 : public Object
{
public:
	MyObject2(void) {};
};

int main ()
{
	Base::TFactory<std::string, Object> lMyFactory;

	lMyFactory.registerPlugin<MyObject1>("MyObject1");
	lMyFactory.registerPlugin<MyObject2>("MyObject2");

	std::vector<std::string> lKeys;
	lMyFactory.getKeys(lKeys);
	std::cout << "Keys:" << std::endl;
	std::copy(lKeys.begin(), lKeys.end(), std::ostream_iterator<std::string>(std::cout, "\n"));

	std::shared_ptr<Object> lObj1SPtr = lMyFactory.makeSharedNewInstance("MyObject1");
	std::unique_ptr<Object> lObj2UPtr = lMyFactory.makeUniqueNewInstance("MyObject2");
}

About

Mit Licence of TFactory template, my Factory DesignPattern without first instantiation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages