Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Factory versus new construction #6

Closed
kitsonk opened this issue Oct 13, 2015 · 5 comments
Closed

Factory versus new construction #6

kitsonk opened this issue Oct 13, 2015 · 5 comments
Milestone

Comments

@kitsonk
Copy link
Member

kitsonk commented Oct 13, 2015

As we were doing the proposal, it was discussed about doing a full factory implementation or following the constructor function pattern and utilise new for instantiation. I got involved in a side conversation at the request of one of the community and @ericelliott took some time to provide some feedback on why new is limiting and a challenge.

I think it is worth considering adopting a factory function as it does give a level of flexibility to the consumer and actually aligns to some of the patterns we were trying to promote anyways.

@kitsonk
Copy link
Member Author

kitsonk commented Oct 14, 2015

The one substantive argument for factories over new is that you do not have to actually create a new instance in the factory. Currently there is no such functionality in the compose proposal to do things like "pooling", but standardising instantiation on new would preclude that pattern in the future.

@maier49
Copy link
Contributor

maier49 commented Oct 30, 2015

I think that in addition to the point about pooling you bring up, there are also some other benefits to using a factory(e.g. being able to bind whatever context you want to a factory function in case you don't want 'this' to reference the new object, and the fact that with new, if somebody is using your library you now can't move to a factory without breaking their code), but I think the most salient reason to use factories is that other than the potential lack of familiarity there's really no downside.

@ericelliott
Copy link

👍

@kitsonk
Copy link
Member Author

kitsonk commented Nov 3, 2015

@maier49 I think you summed it up...

  • new instantiation
    • Benefits - perceived familiarity
    • Disadvantages - If a end user returns a value from a constructor function, it causes wastage which requires cleanup.
  • factories
    • Benefits - pooling, object reuse, more familiar (DOM instantiation is a factory), instance binding, returning Proxies, etc...
    • Disadvantages - none

I will keep this open for a little bit longer, just in case anyone else wants their 2¢.

@kitsonk
Copy link
Member Author

kitsonk commented Nov 16, 2015

Discussion seems complete, so closing.

@kitsonk kitsonk closed this as completed Nov 16, 2015
@dylans dylans added this to the alpha.1 milestone Nov 2, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants