I am Software Developer, currently interested in static type languages (TypeScript, Elm, ReScript) mostly in the frontend land, but working actively in Python also. I am available for mentoring.
Hello Kristijan.
Want to add some things here. You are very much setting a context of this pattern in class based environment. Also implementation use Class with one method. The reality is - factory is just a function, and it simplify data structure creation.
constmakeVehicle=(name,type)=>({name,type});constmakeCar=(name)=>makeVehicle(name,'car');constmakeTruck=(name)=>makeVehicle(name,'truck');// end even more concise by point freeconstmakeVehicle=(type)=>(name)=>({name,type});constmakeCar=makeVehicle('car');constmakeTruck=makeVehicle('truck');
Let me repeat again, factory is just a function which allows in centralized way to create structures in proper shape, thanks to that we are sure that the created object has proper structure and somebody did not missed some fields or done some typo (very often in JS world)
Its simple thing. There is no reason to complicate it.
I agree!
And damn, that code looks nice and neat 😁
Being a backend developer, I am still adjusting to this whole JS.
Would you say I completely missed mark with this or am I on a good path of applying a factory pattern into the JS structure?
Any advice is warm welcomed!
I am Software Developer, currently interested in static type languages (TypeScript, Elm, ReScript) mostly in the frontend land, but working actively in Python also. I am available for mentoring.
It depends what language are you used to. Looking on the example, looks like something very OOP like Java or C#. Not like what you are writing is wrong. Just you need to take into consideration that every time you don't need to use this probably you don't need a class. Keep up with a good work!
Hello Kristijan.
Want to add some things here. You are very much setting a context of this pattern in class based environment. Also implementation use Class with one method. The reality is - factory is just a function, and it simplify data structure creation.
Let me repeat again, factory is just a function which allows in centralized way to create structures in proper shape, thanks to that we are sure that the created object has proper structure and somebody did not missed some fields or done some typo (very often in JS world)
Its simple thing. There is no reason to complicate it.
I agree!
And damn, that code looks nice and neat 😁
Being a backend developer, I am still adjusting to this whole JS.
Would you say I completely missed mark with this or am I on a good path of applying a factory pattern into the JS structure?
Any advice is warm welcomed!
It depends what language are you used to. Looking on the example, looks like something very OOP like Java or C#. Not like what you are writing is wrong. Just you need to take into consideration that every time you don't need to use
this
probably you don't need a class. Keep up with a good work!Thank you! \m/