lundi 24 septembre 2018

Serializing class object to prevent huge contructors inside code

If I have a class with a huge constructor, that independent of what happen will not change (but there will be multiple objects with different data) can I create one object, serialize it and just load the serialized object, instead of having a long chain of constant parameters in the code?

For example, imagine we have the class VeryLongClass, that has a constructor with 50+ parameters, that will not change, but there will be multiple instances of that class that are different between them, so the parameters are needed. Would be acceptable with I created a class instance and serialized it in a file let's say verylongclass1.dat and loaded it when the program started?

Aucun commentaire:

Enregistrer un commentaire