I need to construct objects with many properties. I could create one constructor with one param for each property:
class Friend(name, birthday, phone, address, job, favouriteGame, favouriteBand){
this.name = name;
this.birthday = birthday;
this.phone = phone;
this.address = address;
this.job = job;
this.favouriteGame = favouriteGame;
this.favouriteBand = favouriteBand;
}
or I could recieve one param with a literal object or an array with all the values:
class Friend(descriptor){
this.name = descriptor.name;
this.birthday = descriptor.birthday;
this.phone = descriptor.phone;
this.address = descriptor.address;
this.job = descriptor.job;
this.favouriteGame = descriptor.favouriteGame;
this.favouriteBand = descriptor.favouriteBand;
}
In which case should I use each one? Is there a design-pattern about this subject?
I'm interested in OOP. I'm using Javascript but it could be wrote in any other language supporting OOP (PHP, Java, C++, Python, any other possible)
Aucun commentaire:
Enregistrer un commentaire