Timeline for How to approach separation of layers mapping response to model in Angular app?
Current License: CC BY-SA 4.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 23, 2022 at 7:40 | comment | added | Shad | @JanRecker Could you share the source where you learn this approach and the other approaches? | |
Nov 30, 2020 at 18:15 | comment | added | JanRecker | :-) In my experience the cases were the memory footprint or the CPU usage is more relevant then the readability are a bit rare in modern times. Also, IF there is a performance problem, its much easier to tackle it if the code is understandable. :-) Therefor i first try to make my code nice and shiny, only then i start with a performance analysis and (if really necessary) start to optimize. :-) But as always, three developers, 4 approaches :-) | |
Nov 30, 2020 at 17:48 | comment | added | greatromul | Oh, thanks. I understand the idea. What I actually like is that the mapping methods are close to the model. We can use the advantage of intellisense. We can also decrease the memory footprint using static methods. The footprint itself can be a drawback. For example, mapping service + interface are less memory consumptive. But I actually find your approach good enough in terms of readability. | |
Nov 30, 2020 at 17:40 | vote | accept | greatromul | ||
Nov 30, 2020 at 17:10 | comment | added | JanRecker | The "fromJSON" is static, because the method will create the instance out of the JSON. The "toJSON" is an instance method, because it will take the current instance and create a JSON out of it. You could makte "toJSON" static also, but then the method would need a parameter (''toJSON(instance: User):UserJSON''), because only then it could know WHAT should be converted into a JSON. With a instance method you don´t need that parameter because it knows that it should convert itself. | |
Nov 30, 2020 at 15:43 | comment | added | greatromul | I see, you use static for fromJSON and do not use it for toJSON? Why is there a difference? Do I understand correctly that every instance of the User class will have toJSON method and will not have fromJSON, because the last one belongs to the class itself. Does it make sense to make both static? | |
Oct 27, 2020 at 10:29 | history | answered | JanRecker | CC BY-SA 4.0 |