V2EX  ›  英汉词典
Enqueued related words: Mutator

Getter

释义 Definition

Getter 常指在面向对象编程里用于“获取/读取属性值”的方法(也叫 accessor,取值器/取值方法)。在日常英语中也可泛指“获得某物的人”,但最常见用法出现在编程语境中。

发音 Pronunciation

/ˈɡetər/

例句 Examples

I wrote a getter to read the user’s name.
我写了一个 getter 来读取用户的名字。

The class exposes its fields through getters, which helps keep the internal state controlled.
这个类通过 getters 暴露字段,这有助于让内部状态保持可控。

词源 Etymology

来自动词 get(获得、得到)+ 表示“做某事的人/物”的后缀 -er,字面意思是“获得者/获取者”。在软件工程中引申为“用来获取某个值的方法”。

相关词 Related Words

文学与作品 Literary Works

  • Effective Java(Joshua Bloch)中在讨论 Java 设计与 API 习惯用法时常提到 getters/setters
  • Design Patterns: Elements of Reusable Object-Oriented Software(Gamma 等)在讲解面向对象设计与封装思想时会涉及通过方法访问状态(与 getters 的概念密切相关)。
  • Clean Code(Robert C. Martin)在讨论代码可读性与对象设计时也会谈到类似 getter 的访问方法与其利弊。
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   2143 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 12ms · UTC 14:21 · PVG 22:21 · LAX 06:21 · JFK 09:21
♥ Do have faith in what you're doing.