mercredi 23 mars 2016

Multiple Parameters or is there any way to force use of setters (Java)?

I have a java class named Transactions, with several methods. On in particular, inserts in Sqlite database all values representing a new transaction, something like this:

Date; Time; Category; Payee; Payer; Value; Tags; Description (...)

When I call the method to save a new Transaction, it looks like:

new Transactions().saveNewTransaction(String date, String time, String category, Int Payee, Int Payer, String value, String tags, String Description (...)

I think this method seems big, bad for readable code and the best way would be those fields be as variables from Transactions class and the method saveNewTransaction(), takes no parameters but instead accessing the variables inside the class.

The only problem is: how can I force to a class (In my case an Activity class) call all setters needed to save a new transaction?

The risk would be call saveNewTransaction() and several fields with values not set by the Activity class (at least the method assures all fields must be set by the caller)

Thanks!

Aucun commentaire:

Enregistrer un commentaire