Currently, I have a model class that represents a user.
This class has a constructor that takes an object with all user properties, used, for example, when creating the user. In this case I instantiate the model passing it the necessary information, so its constructor can do the job, then it will use its own createUser
method. Fine.
But in some cases, I don't need to pass all this information to the constructor.
For example, the model has an UdpateCustomUserName
method that just need userId
in order to instantiate from the database and perform this method and update a single field from a single already existing record in the database.
The way I dealt with this is to make the properties
information needed by the constructor optional, so when I need to call UdpateCustomUserName
I just pass to the model the ID and I can instantiate and reach this method.
Is this the proper way of doing it?
Or is it a bad practice to have optional constructor parameters? In this case I would extract UdpateCustomUserName
and keep it in the same module but as a standalone.