Skip to content
Advertisement

Create different request objects dynamically

Is it possible to create different objects dynamically from a superset object. For example:

SuperSet Object:

JavaScript

Child Objects required to be created dynamically from A:

JavaScript

I would like to create such different child classes having different members which are subset of parent class A.

I know the normal way of creating skeleton class for each child object wanted and then map with values from superset object. Instead is there a way to map different parent class member values to child objects members dynamically.

Advertisement

Answer

I am assuming the correspondence stated above is fixed. I mean, field b of Class B will always take the value of A. You can achieve this with a constructor designed accordingly. The code follows,

JavaScript

Now, what happens above is that in the constructor of B you provide A and map the intended values of A onto the intended fields of B. Note, this can be done regardless of the fact that B is or is not a child of A. So, assuming you need to have B as a child of A you can do as follows:

JavaScript

Cheers,

D

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement