vendredi 20 janvier 2017

Is this a design pattern? A class with multiple methods to create different objects from different input formats

Is the following a known design pattern?

I have got Class with multiple methods to create different objects from different input formats.

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)

Aucun commentaire:

Enregistrer un commentaire