Factory pattern implementation