Class and instance variable naming suggestions for a class monitoring a file directory which deletes files when a maximum size has been exceeded

huangapple go评论73阅读模式
英文:

Class and instance variable naming suggestions for a class monitoring a file directory which deletes files when a maximum size has been exceeded

问题

以下是翻译好的部分:

我在寻找适当的类名和表示下面类的实例变量名字有些困难:

该类通过实例化并提供最大和最小大小(以字节为单位),以及表示要监视的目录的 File 对象。 创建了一个 WatchService 用于监视目录中的文件创建事件。

run 方法运行一个无限循环,从监视服务中获取监视事件。 处理每个事件时,如果发现目录大小超过 maxDirectorySize,则删除文件,直到目录大小降至 cleanedDirectorySize 以下。

有人能否建议:

  1. 一个合适的类名?DirectorySizeMonitorAndCleanerTask 是我能想到的最好的,但我仍然不喜欢它。
  2. 一个更好的名称,以更好地表示变量的意图?
英文:

I'm struggling with an appropriate class name and an instance variable name for the class depicted below:

Class and instance variable naming suggestions for a class monitoring a file directory which deletes files when a maximum size has been exceeded

The class is instantiated with a maximum and minimum size (in bytes) and a File object representing a directory to monitor. A WatchService is created to file creation events in the directory.

The run method runs an infinite loop fetching watch events from the watch service. When processing each event, if the directory size is found to exceed maxDirectorySize files are deleted until the directory size falls below cleanedDirectorySize.

Can someone suggest:

  1. an appropriate class name? DirectorySizeMonitorAndCleanerTask is the best I could come up with and I still don't like it
  2. a better name for cleanedDirectorySize that better represents the variable's intent?

答案1

得分: 1

一个你难以找到一个好的类名的原因是你违反了SOLID原则中的单一职责原则。很难为一个具有两个或更多职责的任务命名。

相反,你可以考虑拥有一个DirectoryService类,该类使用定位器模式或依赖注入模式,并将该类组合为DirectorySizeMonitor和DirectoryCleanerTask。然后,该服务可以负责确定何时监视和何时清理,但不知道如何执行任何一个任务。

英文:

One reason why you're struggling to find a good class name is that you're breaking a SOLID principle, single responsibility. It's difficult to name a task that has two or more responsibilities.

You could instead consider having a DirectoryService class that uses the locator pattern or dependency injection pattern and compose that class of DirectorySizeMonitor and DirectoryCleanerTask. That service could then have the single responsibility of determining when to monitor and when to clean, but have no idea how to do either.

答案2

得分: 1

我建议

 DirectoryCapacityWatcher {

      long capacityLowWatermark;
      long capacityHighWatermark;
      ...
 }
英文:

My suggestion

 DirectoryCapacityWatcher {

      long capacityLowWatermark;
      long capacityHighWatermark;
      ...
 }

答案3

得分: 0

一个合适的类名可能是,我认为
TaskSupervisor

英文:

An appropriate name for the class would be I think
TaskSupervisor

答案4

得分: 0

关于 DirectoryJanitorstartCleaningAbovestopCleaningBelow 呢?

英文:

How about DirectoryJanitor, startCleaningAbove and stopCleaningBelow?

huangapple
  • 本文由 发表于 2020年8月27日 00:27:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/63601846.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定