OOP术语:类,属性,属性,字段数据成员 [英] OOP Terminology: class, attribute, property, field, data member

查看:352
本文介绍了OOP术语:类,属性,属性,字段数据成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始学习OOP和我想学习什么构成的类。我如何松散正在使用的一些核心要素,从而增加了我的困惑有点困惑。

I am starting studying OOP and I want to learn what constitutes a class. I am a little confused at how loosely some core elements are being used and thus adding to my confusion.

我已经看过了C ++类,Java类,我想知道足够写我自己的伪类来帮助我理解。

I have looked at the C++ class, the java class and I want to know enough to write my own pseudo class to help me understand.

比如在这篇文章我读到这(..类属性(或类属性,字段或数据成员)

For instance in this article I read this (.. class attribute (or class property, field, or data member)

我见过的比较好切出这表明,有实例<一类属性和类别字段之间的差异问题href=\"http://stackoverflow.com/questions/295104/what-is-the-difference-between-a-field-and-a-property-in-c\">What是一个字段,并在C#中的属性之间的区别?

I have seen rather well cut out questions that show that there is a difference between class property and class field for instance What is the difference between a field and a property in C#?

根据什么语言我学习,是这样定义的

Depending on what language I am studying, is the definition of


  • 属性

  • 字段

  • 类变量

  • 属性

从语言到语言不同?

推荐答案

字段,类变量和属性是的更多或更少的一样 - 一个低级别的存储插槽的附加到对象。每种语言的文档可能一直使用不同的术语,但大多数实际的程序员可以互换使用。 (然而,这也意味着一些术语可以是模糊的,像类变量 - 这可以是PTED为给定的类的实例的变量间$ P $,或类对象本身的可变在语言,其中的类的对象是什么,你可以直接操作。)

"Fields", "class variables", and "attributes" are more-or-less the same - a low-level storage slot attached to an object. Each language's documentation might use a different term consistently, but most actual programmers use them interchangeably. (However, this also means some of the terms can be ambiguous, like "class variable" - which can be interpreted as "a variable of an instance of a given class", or "a variable of the class object itself" in a language where class objects are something you can manipulate directly.)

属性是在我使用的大多数语言,完全是另一回事 - 他们的方式来定制行为附加到读/写的字段。 (或者替代它)。

"Properties" are, in most languages I use, something else entirely - they're a way to attach custom behaviour to reading / writing a field. (Or to replace it.)

因此​​,在Java中,典型的例子是:

So in Java, the canonical example would be:

class Circle {

    // The radius field
    private double radius;
    public Circle(double radius) {
        this.radius = radius;
    }

    // The radius property
    public double getRadius() {
        return radius;
    }
    public double setRadius(double radius) {
        // We're doing something else besides setting the field value in the 
        // property setter
        System.out.println("Setting radius to "+radius);
        this.radius = radius;
    }

    // The circumference property, which is read-only
    public double getCircumference() {
        // We're not even reading a field here.
        return 2 * Math.PI * radius;
    }

}

(注意,在Java中,一个属性是一个叫对存储器方法的getFoo() setFoo() - 或者只是如果属性是只读的吸气剂)

(Note that in Java, a property foo is a pair of accessor methods called getFoo() and setFoo() - or just the getter if the property is read-only.)

这篇关于OOP术语:类,属性,属性,字段数据成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆