Implementation of factory method pattern.