Add factory pattern learning code