OOP: What is the correct terminology for talking about methods and attributes? Both of classes, and their instances? [closed]

StackOverflow https://stackoverflow.com/questions/20622438

  •  02-09-2022
  •  | 
  •  

Say I have a class in a programming language:

class name {

    variable_name = 1;

    method_name(x) {
        // return something
    }
}

foo = new name();

print(foo.method_name(foo.variable_name));

How correct is the following? Can we make it more correct?

  • If I want to talk about a specific instance of a method (foo.method_name), would I say 'the method_name-method of the object foo'? Or something else? Or does talking about the instance of a variable of method make no sense?

  • If I want to talk about a general object of any name, and refer to its method_name-method or variable, what would I say? Would I say 'the method_name-method/variable_name-variable of the class name?' or something else?

Thank you for your time.

Kind regards,

Marius

有帮助吗?

解决方案

  • Talking about a specific instance of a method doesn't really make any sense as you say. Usually we talk about instances of classes - objects - and their methods. Thus one would normally talk about something like "calling method_name on foo" or simply foo dot method_name.

  • That's a fine way of saying it. In my experience it doesn't really matter all that much in day to day communication as the method really does the same thing anyways, just with different values in it's scope. It's what it does that really matters (e.g. accelerate() or toString()). Perhaps the most important part when talking about methods, variables etc. is communicating clearly if they happen to be static - i.e. not belonging to any given instances. In day to day speak I wouldn't make any effort to differentiate very clearly between "then we can just call accelerate on our car instance" and "the car class has a method named accelerate" (it's given that this is a non-static method) - I might however specify that "our car class has a static method to help us calculate acceleration.

其他提示

In a nutshell:

Classes: (which may be instantiated to objects)
   can have - 

       (non-static / instance) members 
                 - public 
                    - methods
                    - properties
                 - private
                    - methods
                    - properties
       (static / class) members
                 - public
                    - methods 
                    - properties
                 - private
                    - methods 
                    - properties

However, methods have/can also be called messages, selectors, or behaviours (depending on the language in question, and in particular contexts.) It's occasionally considered incorrect to call them functions, however no one in their right mind should take you to task over such things. (notably the appearance of the keyword function in ECMAScript shows its level of acceptability. As a rule of thumb, the language domain would always define correctness, otherwise generally the term is fine/understandable but can lead to ambiguity.) Similarly properties are variously called, fields, attributes or variables.

An alternative name for non-static methods or properties is to call them instance methods or properties. While static methods / properties may be referred to as class methods / properties. By the way, ommitting the non-static qualifier, is usual and implicit.

As a general guideline, refer to the language under use to determine the correct terms, as they are specific to the various language cultures.

The assumption in writing this, is that there's no need to outline the scope/access differences of these class members. If that's required, I'd be happy to add a note.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top