This is an implementation of factory pattern via macro function and template.