Factory design pattern implemenation.