Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • But how would I get IntroSlide based off of "slideType": "intro" in the json? Commented Jan 10 at 19:57
  • @Hello are you asking about this? Commented Jan 10 at 20:01
  • No, you say it's ok to call out what you want by name. But it's not hard coded, I want to create objects based off some json I fetch from an endpoint. Say if I have "slideType": "intro" in the json, how would I map it to the appropriate subclass of Slide (being IntroSlide)? Commented Jan 11 at 6:05
  • @Hello json can serialize objects. But if you insist on strings then mapping from the string "intro" to an IntroSlide object can be done with a simple {key:value} map. I'm not 100% clear what you're trying to accomplish with this. Commented Jan 11 at 19:43
  • I am clear with (de)serialization. The question is about what is the best approach that alignes with OOP to create the object of the appropriate subclass that extends from Slide from the slideType in the json. I also said in the question I can create a factory that maps all types to their appropriate Slide objects but that would require me updating it every time I create a new subclass Commented Jan 12 at 11:11