Naming conventions for private virtual methods

Discussion in 'C++' started by Daniel, Feb 14, 2014.

  1. Daniel

    Daniel Guest

    I know, nobody likes this kind of question, but there aren't many questions these days, so ...

    Consider a case of private virtual inheritance where the motivation is to have overloading on the preferred method name "value".

    class base
    {
    public:
    void value(int val)
    {
    // calls value_
    }
    void value(long val)
    {
    // calls value_
    }
    void value(long long val)
    {
    // calls value_
    }
    private:
    virtual void value_(long long val) = 0;
    };

    class derived : public base
    {
    private:
    // implements value_
    };

    Can anyone suggest a reasonable naming convention for the overridable private method value_? I've seen variants of "doValue", "value_long_long", and "value_event". Any commonly used conventions?

    Thanks,
    Daniel
     
    Daniel, Feb 14, 2014
    #1
    1. Advertisements

  2. There is no private virtual inheritance in your post, just so we talk
    about the same thing, a private virtual inheritance is this relationship
    between classes A and B:

    class A { ... };
    class B : virtual A { ... };

    to have overloading on the preferred method name "value".
    From the implementation 'value' here is a "setter", so it might make
    sense to indicate that.

    Another argument is that the overloaded function shall be specific to
    each class deriving from 'base', so it might make sense to add
    "specific" to it (either as a suffix or as a prefix).

    And of course I admit that I am not aware of any convention you're
    alluding to in your message. If there exists something of that sort, I
    have never come across it, or cannot recall such an occurrence.

    V
     
    Victor Bazarov, Feb 14, 2014
    #2
    1. Advertisements

  3. Daniel

    Öö Tiib Guest

    I prefer to avoid setters; when still needed I prefer to indicate that
    in name as "set value". Getters I prefer to name just "value". For
    private virtual I use prefix "do" so for your example ... "do set value".

    Note that it is about naming so usually I follow whatever conventions
    code-base under work already uses. There are no "ultimate"
    conventions. There can be convention or there can be awful mess caused
    by people with different "ultimates".
     
    Öö Tiib, Feb 14, 2014
    #3
  4. Daniel

    Daniel Guest

    That's helpful, thanks,
    Daniel
     
    Daniel, Feb 14, 2014
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.