Skip to content

Instantly share code, notes, and snippets.

@bearprada
Last active January 30, 2019 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bearprada/35c91da5e9862a2c6b5b88735accdc7d to your computer and use it in GitHub Desktop.
Save bearprada/35c91da5e9862a2c6b5b88735accdc7d to your computer and use it in GitHub Desktop.

Scope (large -> small) : Repository > Store > Factory > Others

Class Name Read Write Comment
store Y Y Provide cache machanism. imply signlton pattern
repository Y Y the same as store, but repository have more features rather than the read/write data, e.g, update/delete data, provide metadata to archive some business goal, e,g. latest update time, sorting the items based on some rules.
source Y N get the results when calling it
provider Y N provide the real implementation, we use it when we try to inject the dependencies(eliminate it)
factory Y N imply Factory pattern, reduce the complexity of creating objects
creator Y N might the same as Factory(eliminate it)
@jcham
Copy link

jcham commented Jan 30, 2019

Actually I would disagree somewhat with Store. In the Redux sense of the it does imply a Singleton pattern, but it has nothing to do with Caches. If the primary function of something is to be a Cache it should be called Cache. I think the Redux sense of it is more about "single source of truth/state".

That said, in general usage, I prefer the philosophy of asking "what does it do?" (notice I always ask that during review meetings). If the answer is "it stores X", then sure, call it XStore.

(There is also the meaning of "Store" that sells things, such as "StickerStore", but that's another story).

Repository is more accurate.

Source the issue is not who calls it, but that it produces a series of things.

Factory is about abstracting the construction of instances, whether for Dependency Injection or because the construction is complex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment