以下是一种已知的设计模式吗?
我有 Class ,有多种方法可以从不同的输入格式创建不同的对象。
E.g. Apologise for the pseudocode
// Definition
CreatorClass() {
func createCat(input -> array) -> Cat{
Cat aCat = Cat()
//...initialisation from array
return aCat;
}
func createCat(input -> containerClass){
Cat aCat = Cat()
//...initialisation from containerClass
return aCat;
}
func createCat(input -> dictionary){
Cat aCat = Cat()
//...initialisation from dictionary
return aCat;
}
func createDog(input -> dictionary){
Dog aDog = Dog()
//...initialisation from dictionary
return aDog;
}
}
// Usage
Creator aCreator = Creator()
Cat aCat = aCreator.createCat(array)