较小的方法

All*_*nde 4 java methods refactoring coding-style

按照鲍勃·马丁叔叔在"清洁代码"中给出的指导原则,我试图让我的方法更小.

他给出的一个建议是,包含trys的方法应该调用其他不涉及异常情况的方法.

我的问题是命名.

通常在我的方法只包含try表达式的时候,剩下的不多了,方法的名称完美地描述了它除了异常之外的作用.

您使用哪些约定来命名特殊人员将调用的"非例外"方法?

举个例子,这是我正在研究的方法:

private void generateAndAttachDocumentFromTemplate(File templateFile) {
  try {
    File generatedDocument = generateDocumentFromTemplate(templateFile);
    if (generatedDocument != null) {
      attachDocument(generatedDocument, container);

      attachmentsPanel.reload();

      SystemControl.openDocument(generatedDocument);
    }
  } catch (Exception ex) {
    Notifier.notifyIT(App.user().getEmail(), ex);
    Dialogs.complain("Can\'t Generate Document");
  }
}
Run Code Online (Sandbox Code Playgroud)

wil*_*ood 5

我使用的方法(我认为他在书中建议)你有methodNametryMethodName.