重复与现有

说我想插入一个产品。
但是,在插入它之前,我需要检查其名称在表产品中是否已经存在。

合适的方法名称是什么?我对此有些困惑。

VirtualService

对不起,如果有语法错误。

mingmingpi2009 回答:重复与现有

根据优雅对象(第1卷):Yegor Bugayenko ,通常,方法有两种。

  1. 构建器方法

    这些方法会构建一些东西并返回一个新对象。

    他们的名字必须是一个名词。

    Student student (Long id);
    List<Car> cars ();
    Long salary(Long id);
    
  2. 操纵器方法

    这些方法总是对数据进行修改,什么也不返回。(总是返回 void

    他们的名字必须是动词。

    void save(Student student);
    void print(String name);
    void delete (Long id);
    void persist(Student student);
    

因此,构建器进行构建并由操纵器进行操纵

返回 boolean 的方法有一个例外。 对于这种类型的方法,最好使用形容词进行命名。

   boolean empty();
   boolean existent(Long id);

我建议您在方法命名中使用形容词,并且在命名中不要使用 “是”

您的方法名称可以是:

boolean productExistent(String name);
boolean productNameExistent(String name);
boolean nameExistent(String name);
boolean existent(String name);
,

方法应为动词,大小写混合,首字母小写,每个内部单词的首字母大写。 ref.code-conventions-135099

基于此,您可能正在使用isDuplicate()isExisting()isDuplicatedName()isExistingName()

,

.isDuplicated(_name)听起来像您已经拥有了多个具有给定名称的实体。 .isExist(_name)返回true> 0。

这些用于不同情况的方法。

本文链接:https://www.f2er.com/2791831.html

大家都在问