java - Write variables automatically into child class -


i’m trying achieve following. have several model has basic methods, such savemodel, loadmodel, laodmodel from. now, have other classes extend model, e.g. user , movie.

user has variables

id username usermail userpw 

movie has

id movietitle movielength moviegenre 

now, create new user object , load database. when load model movie, have json-object containing following information:

id = x movietitle = "bla" movielength = "bla" moviegenre = "bla" 

as can see, json contains correct key , values, have write them child model. how possible, model writes field values user object? in php this

foreach ($row $key=>$val) {             $this->$key = $val; } 

in java, doesn’t seem possible. how can parent class automatically write variables child class. or isn’t possible , have manually? problem see here, is, have every model again, when in super class. how that?

one way achieve define parent class have maps holding possible fields; , have child class define fields contained in enums. parent class level serialize maps , key-value pairs. use generic enum parameter give flexibility on key / key type use.

having said so, it's best have code generator generates child classes; if wish, can generate individual method each field pointing specific key in maps well.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -