Skip to main content
Code Review

Return to Answer

deleted 7 characters in body
Source Link
200_success
  • 145.5k
  • 22
  • 190
  • 478

It's not so much a question of best practices, but rather a question of correctness. From my understanding of the problem you are trying to solve, making using static variables for CSVFilePath and HTMLReport would be incorrect, since (I assume) their values depend on the jsonFilePath passed into the Reporter's constructor. If you had multiple Reporters, each monitoring a different JSON file, each Reporter would have a different CSVFilePath and HTMLReport — hence, they should be instance variables, not class variables.

That said, instance methods rarely use class variables, unless the class variables are const or readonly. If your instance method does use a static variable, you should at least rethink what you are doing, and why.

If you only expect to ever create one Reporter in your system, look into making Reporter a singleton.

It's not so much a question of best practices, but rather a question of correctness. From my understanding of the problem you are trying to solve, making using static variables for CSVFilePath and HTMLReport would be incorrect, since (I assume) their values depend on the jsonFilePath passed into the Reporter's constructor. If you had multiple Reporters, each monitoring a different JSON file, each Reporter would have a different CSVFilePath and HTMLReport — hence, they should be instance variables, not class variables.

That said, instance methods rarely use class variables, unless the class variables are const or readonly. If your instance method does use a static variable, you should at least rethink what you are doing, and why.

If you only expect to ever create one Reporter in your system, look into making Reporter a singleton.

It's not so much a question of best practices, but rather a question of correctness. From my understanding of the problem you are trying to solve, using static variables for CSVFilePath and HTMLReport would be incorrect, since (I assume) their values depend on the jsonFilePath passed into the Reporter's constructor. If you had multiple Reporters, each monitoring a different JSON file, each Reporter would have a different CSVFilePath and HTMLReport — hence, they should be instance variables, not class variables.

That said, instance methods rarely use class variables, unless the class variables are const or readonly. If your instance method does use a static variable, you should at least rethink what you are doing, and why.

If you only expect to ever create one Reporter in your system, look into making Reporter a singleton.

Source Link
200_success
  • 145.5k
  • 22
  • 190
  • 478

It's not so much a question of best practices, but rather a question of correctness. From my understanding of the problem you are trying to solve, making using static variables for CSVFilePath and HTMLReport would be incorrect, since (I assume) their values depend on the jsonFilePath passed into the Reporter's constructor. If you had multiple Reporters, each monitoring a different JSON file, each Reporter would have a different CSVFilePath and HTMLReport — hence, they should be instance variables, not class variables.

That said, instance methods rarely use class variables, unless the class variables are const or readonly. If your instance method does use a static variable, you should at least rethink what you are doing, and why.

If you only expect to ever create one Reporter in your system, look into making Reporter a singleton.

lang-cs

AltStyle によって変換されたページ (->オリジナル) /