プリンキピア

第4章アルゴリズムの言語による実現:低水準プログラミング言語

Object-Oriented Programmingオブジェクト指向プログラミング
Object-oriented code is organized around objects. An object has both data, or variables, and procedures that work together to represent a specific human concept. For example, in a desktop or mobile application, every button on the screen is an object. Each button has variables to represent information, such as the location and color of the button, and procedures that perform tasks, such as clicking, hiding, or displaying the button. This programming paradigm is known as object-oriented programming. It is a programming paradigm in which code is organized into objects, where each object has both data and procedures. It is a sub-type of procedural programming. All object-oriented languages, then, are procedural (and by extension, imperative), but not all procedural languages are object-oriented. A simple example of an object can be a rectangle used to represent meaningful concepts in real life, such as the rooms in a house or a person or robot and what it can do. Different rooms may have different attributes, representing features that are specific to a kitchen, a living room, or a bedroom. A robot can have a name and age and can receive input commands and respond or print a greeting, as illustrated in Figure 4.14.
英語のヒント
オブジェクト指向のコードは、オブジェクトを中心に整理される。オブジェクトは、データ、つまり変数と手続きの両方を持ち、それらが連携して、人間が考える特定の概念を表す。たとえばデスクトップやモバイルのアプリケーションでは、画面上の各ボタンがオブジェクトである。ボタンには位置や色などの情報を表す変数と、クリック、非表示、表示などの仕事をする手続きがある。これがオブジェクト指向プログラミングと呼ばれるパラダイムである。コードを、データと手続きの両方を持つオブジェクトに整理する。手続き型プログラミングの一種なので、オブジェクト指向言語はすべて手続き型であり、ひいては命令型でもあるが、すべての手続き型言語がオブジェクト指向とは限らない。オブジェクトの単純な例として、現実に意味を持つ概念、たとえば家の部屋や、人やロボットとそれができることを表す長方形が挙げられる。部屋ごとに、台所、居間、寝室などに固有の特徴を表す、異なる属性があるかもしれない。図4.14のように、ロボットは名前と年齢を持ち、入力命令を受け取り、応答したり挨拶を表示したりできる。
Figure 4.14

attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license · CC BY 4.0 · Source出典

Figure 4.14 The object-oriented use of a robot class instantiates robot objects that have attributes of age, name, and greeting and methods of input(), output(), and print(). (attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license)
図4.14 オブジェクト指向でrobotクラスを使うと、年齢、名前、挨拶の属性と、input()、output()、print()のメソッドを持つ、ロボットのオブジェクトを生成する。(出典表記:著作権者 Rice University、OpenStax、CC BY 4.0ライセンス)
Object-oriented programming was invented to help programmers organize their code, and it has been very successful. The most widely used high-level languages, including C++, C#, Java, JavaScript, and Swift, are all object-oriented. Object-oriented programming is discussed further in Chapter 7 High-Level Programming Languages.
オブジェクト指向プログラミングは、プログラマーがコードを整理しやすくするために考案され、大きな成功を収めてきた。C++、C#、Java、JavaScript、Swiftなど、最も広く使われる高水準言語は、すべてオブジェクト指向である。第7章「高水準プログラミング言語」で、さらに詳しく扱う。