Factory pattern applied and tested