Use template and factory pattern