与其把类命名为ABCService, 不如叫AbcService

ABC是个专有名词,一般情况下对应的service应该叫做ABCService; 然而,我建议还是叫AbcService,否则对应的实例名会很别扭:

    private ABCService aBCService;
    public void setABCService(ABCService aBCService) {
        this.aBCService = aBCService;
    }

你会说变量名可以这样写:

    private ABCService abcService;
    public void setAbcService(ABCService abcService) {
        this.abcService = abcService;
    }

这当然没问题。但很多代码生成器会因此失效,因为这些工具一般都期望类名和实例名只有第一个字母的大小写不同。

所以,还不如换成AbcService,虽然这种命名中失去了“专有名词”的信息,但可以保证你写代码的流畅度:

    private AbcService abcService;
    public void setAbcService(AbcService abcService) {
        this.abcService = abcService;
    }

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.