简体   繁体   English

命名约定-需要帮助

[英]naming convention - need help

I am writing different classes for a booking system. 我正在为预订系统编写不同的类。 The 1st class I named is Room Room has different attributes like SingleRoom, DoubleRoom and DobuleRoom with Baby. 我命名的第一类是Room Room,它具有不同的属性,例如SingleRoom,DoubleRoom和DobabeRoom with Baby。 And another Class is named a Person which contains name, age etc. 另一个类名为Person ,其中包含姓名,年龄等。

Now a DoubleRoom with allows max 2 adults with or without a baby. 现在,双人房最多可容纳2位成人(有或没有婴儿)。 And in SingleRoom I am allowed to add only single adult (no baby) 在SingleRoom中,我只能添加一个成年人(没有婴儿)

I want to name the methods accoding to best practices. 我想命名遵循最佳实践的方法。 I need the suggestion for possible methods and there names. 我需要可能的方法和那里的名字的建议。

For methods on classes I generally use the "action+property" convention, which is the standard by most developers. 对于类上的方法,我通常使用“动作+属性”约定,这是大多数开发人员的标准。 For example, 例如,

<?php

class Room
{
    public function getName() {}
    public function setName($name) {}
    public function addPerson($person) {}
    public function removePerson($person) {}
    public function addChild($child) {}
    // etc
}

As you can see, you are stating what you are doing, and then what you are manipulating by that action. 如您所见,您正在陈述自己在做什么,然后通过该操作来操纵什么。

As for the actual name, I more or less always adopt CamelCase . 至于实际名称,我或多或少总是采用CamelCase

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM