lundi 11 janvier 2016

Factory vs Class when to use which? [on hold]

After gaining a firm grasp of core JavaScript including classical inheritance and all of the "fun" gotchas, I came across design patterns. I have been hearing all kinds of chatter about moving away from classes and constructors.

Then I came across the a Factory design pattern that didn't use constructors or the new operator. This had a lot implications. Objects were less tightly coupled - mostly because my inheritance hierarchy got smaller. I could change the parents and worry less about breaking the children. I didn't have to use call, bind, and apply, as much.

So now I wonder a few things:

  • Can the Factory design pattern completely replace the class?
  • If classes still have a place in JavaScript, where is it best to use them?
  • I know that classes are nicely optimized by the VM, so is there a way to get the benefits of both?
  • Where does the the prototype property instance.prototype.myProperty fit into Factory design patterns?

This may be a slightly broad question but, this seems like the best place to ask it. I'm not trying to start a flame war. I am not asking which design pattern is better. I welcome links to articles and opinions.

Aucun commentaire:

Enregistrer un commentaire