Open m7vicente opened 4 years ago
Agree. I think a better name would be build
or buildFrom
What do you think?
The most intuitive is buildFrom
, but i think the best way to create a entity from a object is from constructor parameters , like new User(obj)
.
what about `newFrom'?
const user = new User.newFrom({ ...input });
or just from
const user = new User.from({ ...input });
still open to suggestions
I believe that .build or .create should be better than .from ... Because it already is used in other libs like own javascript...
just to add to this discussion...
There are only two hard things in Computer Science: cache invalidation and naming things. -- Phil Karlton
there are two approaches towards naming:
const user = new User.create({ ...input });
const user = new User.from({ ...input });
in (1) create
captures the intetion of the method, but doesn't look that nice when reading the code
in (2) it is a attempt to capture the intention "create a new User from this data" in code and make it more readable
In most cases we use of this method to create an entity instance-based from any object, it can be from a database or a simple post request, in some ways, the object has been constructed previously, so User.from(obj)
, make more sense, because it's not a literal new object.
Ohh, got it! This really make sense. Now new User.createFrom( param )
seems to be an option...
createFrom
seems to mix both ideas. I'm not sure it's the way to go...
lets use just
User.from(param), this way, in the future we can create other constructors like
User.FromXml(xmlParam)`, and we let the users create customized constructors methods for an entity using the same pattern.
I think it's related with issue https://github.com/herbsjs/gotu/issues/14
The serialization method 'fromJSON' is capable to parse in entity not only json strings, but entire objects, so, it should be called 'fromObject'.