mercredi 16 mars 2016

Class taking itself as a parameter of the constructor

I've seen similar questions but most of the time it doesn't have the same implications or nuances

public class Dog {
  public Dog(Animal animal) {
    this.name = animal.name;
    this.age = animal.age;
    ....
  }
  public Dog(Dog dog) {
    this.name = dog.name;
    this.age = dog.name;
  }
}

I saw this written by a colleague on several occasions in different contexts but have yet to see any value in the second constructor... I was wondering if there were any reasons why this type of structure pattern is good/bad/otherwise.

Aucun commentaire:

Enregistrer un commentaire