[perldocjp-cvs 1829] CVS update: docs/perl/5.16.1

Back to archive index

argra****@users***** argra****@users*****
2013年 11月 6日 (水) 01:35:51 JST


Index: docs/perl/5.16.1/perlootut.pod
diff -u docs/perl/5.16.1/perlootut.pod:1.1 docs/perl/5.16.1/perlootut.pod:1.2
--- docs/perl/5.16.1/perlootut.pod:1.1	Fri Nov  1 04:02:15 2013
+++ docs/perl/5.16.1/perlootut.pod	Wed Nov  6 01:35:50 2013
@@ -37,12 +37,10 @@
 
 =end original
 
-This document provides an introduction to object-oriented programming
-in Perl. It begins with a brief overview of the concepts behind object
-oriented design. Then it introduces several different OO systems from
-L<CPAN|http://search.cpan.org> which build on top of what Perl
-provides.
-(TBT)
+この文書は Perl でのオブジェクト指向プログラミングを紹介します。
+これはオブジェクト指向設計の背後にあるコンセプトの概説から始めます。
+それから Perl が提供するものの上に構築されている、
+L<CPAN|http://search.cpan.org> にあるいくつかの OO システムを紹介します。
 
 =begin original
 
@@ -54,12 +52,12 @@
 
 =end original
 
-By default, Perl's built-in OO system is very minimal, leaving you to
-do most of the work. This minimalism made a lot of sense in 1994, but
-in the years since Perl 5.0 we've seen a number of common patterns
-emerge in Perl OO. Fortunately, Perl's flexibility has allowed a rich
-ecosystem of Perl OO systems to flourish.
-(TBT)
+デフォルトでは、Perl の組み込みの OO システムはとても最小限で;
+ほとんどの作業を自分でする必要があります。
+この最小限主義は 1994 年には十分意味のあるものでしたが、Perl 5.0 から
+時が経つにつれて、Perl OO に多くの共通のパターンが見られるようになりました。
+幸い、Perl の柔軟性により、Perl OO システムの豊かなエコシステムが
+発展しました。
 
 =begin original
 
@@ -68,9 +66,8 @@
 
 =end original
 
-If you want to know how Perl OO works under the hood, the L<perlobj>
-document explains the nitty gritty details.
-(TBT)
+裏で Perl OO がどのように動作するのかを知りたい場合は、L<perlobj> 文書が
+本質的な詳細について説明しています。
 
 =begin original
 
@@ -81,11 +78,11 @@
 
 =end original
 
-This document assumes that you already understand the basics of Perl
-syntax, variable types, operators, and subroutine calls. If you don't
-understand these concepts yet, please read L<perlintro> first. You
-should also read the L<perlsyn>, L<perlop>, and L<perlsub> documents.
-(TBT)
+この文書は、Perl の文法、変数型、演算子、サブルーチン呼び出しの基本について
+既に理解していると仮定しています。
+まだこれらのコンセプトについてまだ理解していないなら、まず L<perlintro> を
+読んでください。
+L<perlsyn>, L<perlop>, L<perlsub> 文書も読むべきでしょう。
 
 =head1 OBJECT-ORIENTED FUNDAMENTALS
 
@@ -102,13 +99,12 @@
 
 =end original
 
-Most object systems share a number of common concepts. You've probably
-heard terms like "class", "object, "method", and "attribute" before.
-Understanding the concepts will make it much easier to read and write
-object-oriented code. If you're already familiar with these terms, you
-should still skim this section, since it explains each concept in terms
-of Perl's OO implementation.
-(TBT)
+ほとんどのオブジェクトシステムは多くの共通の概念を共有しています。
+おそらく以前に「クラス」、「オブジェクト」、「メソッド」、属性といった
+用語について聞いたことがあるでしょう。
+概念の理解は、オブジェクト指向のコードを読み書きするよりも遥かに容易です。
+既にこれらの用語に親しんでいるでも、この章を流し読みするべきです; なぜなら
+Perl の OO 実装の用語でそれぞれの概念を説明しているからです。
 
 =begin original
 
@@ -120,12 +116,12 @@
 
 =end original
 
-Perl's OO system is class-based. Class-based OO is fairly common. It's
-used by Java, C++, C#, Python, Ruby, and many other languages. There
-are other object orientation paradigms as well. JavaScript is the most
-popular language to use another paradigm. JavaScript's OO system is
-prototype-based.
-(TBT)
+Perl の OO システムはクラスベースです。
+クラスベース OO はかなり一般的です。
+これは Java, C++, C#, Python, Ruby およびその他の多くの言語で使われています。
+その他のオブジェクト指向パラダイムもあります。
+JavaScript は、その他のパラダイムを使っている最も有名な言語です。
+JavaScript の OO システムはプロトタイプベースです。
 
 =head2 Object
 
@@ -140,11 +136,12 @@
 
 =end original
 
-An B<object> is a data structure that bundles together data and
-subroutines which operate on that data. An object's data is called
-B<attributes>, and its subroutines are called B<methods>. An object can
-be thought of as a noun (a person, a web service, a computer).
-(TBT)
+B<オブジェクト> は、データと、そのデータを操作するサブルーチンを一つに
+まとめたデータ構造です。
+オブジェクトのデータは B<属性> と呼ばれ、サブルーチンは B<メソッド> と
+呼ばれます。
+オブジェクトは名詞と考えることができます (人、web サービス、
+コンピュータなど)。
 
 =begin original
 
@@ -158,14 +155,13 @@
 
 =end original
 
-An object represents a single discrete thing. For example, an object
-might represent a file. The attributes for a file object might include
-its path, content, and last modification time. If we created an object
-to represent F</etc/hostname> on a machine named "foo.example.com",
-that object's path would be "/etc/hostname", its content would be
-"foo\n", and it's last modification time would be 1304974868 seconds
-since the beginning of the epoch.
-(TBT)
+オブジェクトは単一のものを表現します。
+たとえば、あるオブジェクトがファイルを表現しているとします。
+ファイルオブジェクトの属性はパス、内容、最終更新時刻といったものになります。
+オブジェクトのパスが "/etc/hostname" になるような、
+"foo.example.com" という名前のマシンの F</etc/hostname> を表現する
+オブジェクトを作る場合、その内容は "foo\n" で、最終更新時刻は紀元から
+1304974868 秒といったものになります。
 
 =begin original
 
@@ -174,9 +170,8 @@
 
 =end original
 
-The methods associated with a file might include C<rename()> and
-C<write()>.
-(TBT)
+ファイルに結びつけられたメソッドは C<rename()> や C<write()> と
+いったものになります。
 
 =begin original
 
@@ -186,10 +181,9 @@
 
 =end original
 
-In Perl most objects are hashes, but the OO systems we recommend keep
-you from having to worry about this. In practice, it's best to consider
-an object's internal data structure opaque.
-(TBT)
+Perl ではほとんどのオブジェクトはハッシュですが、推奨する OO システムは
+これについて気にする必要がないようにします。
+実際には、オブジェクトの内部構造は不透明であると考えるのが最良です。
 
 =head2 Class
 
@@ -203,10 +197,9 @@
 
 =end original
 
-A B<class> defines the behavior of a category of objects. A class is a
-name for a category (like "File"), and a class also defines the
-behavior of objects in that category.
-(TBT)
+B<クラス> はあるカテゴリのオブジェクトの振る舞いを定義します。
+クラスは("File" のような)カテゴリを表す名前です; またクラスは
+そのカテゴリのオブジェクトの振る舞いを定義します。
 
 =begin original
 
@@ -218,12 +211,12 @@
 
 =end original
 
-All objects belong to a specific class. For example, our
-F</etc/hostname> object belongs to the C<File> class. When we want to
-create a specific object, we start with its class, and B<construct> or
-B<instantiate> an object. A specific object is often referred to as an
-B<instance> of a class.
-(TBT)
+全てのオブジェクトは何らかのクラスに属します。
+例えば、F</etc/hostname> オブジェクトは C<File> クラスに属します。
+特定のオブジェクトを作りたい場合、そのクラスから始めて、オブジェクトを
+B<構築>(construct) または B<インスタンス化> (instantiate) します。
+特定のオブジェクトはしばしばクラスの B<インスタンス> (instance) と
+呼ばれます。
 
 =begin original
 
@@ -233,10 +226,10 @@
 
 =end original
 
-In Perl, any package can be a class. The difference between a package
-which is a class and one which isn't is based on how the package is
-used. Here's our "class declaration" for the C<File> class:
-(TBT)
+Perl では、どのパッケージもクラスになれます。
+クラスであるパッケージと層でないパッケージの違いは、パッケージがどのように
+使われるかによります。
+以下は C<File> クラスのための「クラス宣言」です:
 
   package File;
 
@@ -248,10 +241,9 @@
 
 =end original
 
-In Perl, there is no special keyword for constructing an object.
-However, most OO modules on CPAN use a method named C<new()> to
-construct a new object:
-(TBT)
+Perl では、オブジェクトの構築のための特別なキーワードはありません。
+しかし、CPAN のほとんどの OO モジュールは、新しいオブジェクトの構築に
+C<new()> という名前のメソッドを使います:
 
   my $hostname = File->new(
       path          => '/etc/hostname',
@@ -266,9 +258,7 @@
 
 =end original
 
-(Don't worry about that C<< -> >> operator, it will be explained
-later.)
-(TBT)
+(C<< -> >> 演算子について心配しないでください; 後で説明します。)
 
 =head3 Blessing
 
@@ -283,11 +273,10 @@
 
 =end original
 
-As we said earlier, most Perl objects are hashes, but an object can be
-an instance of any Perl data type (scalar, array, etc.). Turning a
-plain data structure into an object is done by B<blessing> that data
-structure using Perl's C<bless> function.
-(TBT)
+既に述べたように、ほとんどの Perl オブジェクトはハッシュですが、
+オブジェクトはどの Perl データ型 (スカラ、配列など)のインスタンスも可能です。
+普通のデータ構造のオブジェクトへの変換は、データ構造に Perl の C<bless> 関数を
+使うことによる B<bless> によって行われます。
 
 =begin original
 
@@ -298,11 +287,10 @@
 
 =end original
 
-While we strongly suggest you don't build your objects from scratch,
-you should know the term B<bless>. A B<blessed> data structure (aka "a
-referent") is an object. We sometimes say that an object has been
-"blessed into a class".
-(TBT)
+一からオブジェクトを構築しないことを強く勧めますが、B<bless> という
+用語は知っておくべきです。
+B<bless された> データ構造 (またの名を「リファレンス先」)はオブジェクトです。
+時々、オブジェクトは「クラスに bless された」と表現します。
 
 =begin original
 
@@ -312,10 +300,10 @@
 
 =end original
 
-Once a referent has been blessed, the C<blessed> function from the
-L<Scalar::Util> core module can tell us its class name. This subroutine
-returns an object's class when passed an object, and false otherwise.
-(TBT)
+一旦リファレンス先が bless されると、L<Scalar::Util> コアモジュールの
+C<blessed> 関数はそのクラス名を返します。
+このサブルーチンは、オブジェクトが和されるとオブジェクトのクラスを返し、
+さもなければ偽を返します。
 
   use Scalar::Util 'blessed';
 
@@ -335,11 +323,10 @@
 
 =end original
 
-A B<constructor> creates a new object. In Perl, a class's constructor
-is just another method, unlike some other languages, which provide
-syntax for constructors. Most Perl classes use C<new> as the name for
-their constructor:
-(TBT)
+B<コンストラクタ> は新しいオブジェクトを作成します。
+コンストラクタのための文法を提供しているその他の言語と異なり、Perl では
+クラスのコンストラクタは単なるメソッドです。
+ほとんどの Perl クラスはコンストラクタの名前として C<new> を使います:
 
   my $file = File->new(...);
 
@@ -356,11 +343,10 @@
 
 =end original
 
-You already learned that a B<method> is a subroutine that operates on
-an object. You can think of a method as the things that an object can
-I<do>. If an object is a noun, then methods are its verbs (save, print,
-open).
-(TBT)
+オブジェクトを操作するサブルーチンが B<メソッド> であるということは
+既に学んでいます。
+メソッドはオブジェクトが I<する> ことと考えることができます。
+オブジェクトが名詞なら、メソッドは動詞 (保存する、表示する、開く) です。
 
 =begin original
 
@@ -370,10 +356,8 @@
 
 =end original
 
-In Perl, methods are simply subroutines that live in a class's package.
-Methods are always written to receive the object as their first
-argument:
-(TBT)
+Perl では、メソッドは単にクラスのパッケージにあるサブルーチンです。
+メソッドは常に最初の引数としてオブジェクトを受け取るように書かれます:
 
   sub print_info {
       my $self = shift;
@@ -391,9 +375,9 @@
 
 =end original
 
-What makes a method special is I<how it's called>. The arrow operator
-(C<< -> >>) tells Perl that we are calling a method.
-(TBT)
+メソッドを特別なものにしているのは、I<どのように呼び出されるか> です。
+矢印演算子 (C<< -> >>) は、メソッドとして呼び出していることを Perl に
+知らせます。
 
 =begin original
 
@@ -404,11 +388,12 @@
 
 =end original
 
-When we make a method call, Perl arranges for the method's B<invocant>
-to be passed as the first argument. B<Invocant> is a fancy name for the
-thing on the left side of the arrow. The invocant can either be a class
-name or an object. We can also pass additional arguments to the method:
-(TBT)
+メソッド呼び出しをするとき、Perl はメソッドの B<呼び出し元> (invocant) を
+最初の引数として渡すように用意します。
+to be passed as the first argument. 
+B<呼び出し元> とは矢印の左側にあるものの名前です。
+呼び出し元はクラス名とオブジェクトのどちらかです。
+また、メソッドに追加の引数も渡せます:
 
   sub print_info {
       my $self   = shift;
@@ -432,10 +417,10 @@
 
 =end original
 
-Each class can define its B<attributes>. When we instantiate an object,
-we assign values to those attributes. For example, every C<File> object
-has a path. Attributes are sometimes called B<properties>.
-(TBT)
+各クラスは B<属性> を定義します。
+オブジェクトをインスタンス化するとき、これらの属性に値を代入します。
+例えば、各 C<File> オブジェクトはパスを持ちます。
+属性は時々 B<プロパティ> (properties) と呼ばれます。
 
 =begin original
 
@@ -445,10 +430,9 @@
 
 =end original
 
-Perl has no special syntax for attributes. Under the hood, attributes
-are often stored as keys in the object's underlying hash, but don't
-worry about this.
-(TBT)
+Perl には属性のための特別な文法はありません。
+内部では、属性はしばしばオブジェクトの基となっているハッシュのキーとして
+保管されますが、これについて気にすることはありません。
 
 =begin original
 
@@ -459,11 +443,11 @@
 
 =end original
 
-We recommend that you only access attributes via B<accessor> methods.
-These are methods that can get or set the value of each attribute. We
-saw this earlier in the C<print_info()> example, which calls C<<
-$self->path >>.
-(TBT)
+属性には B<アクセサ> (accessor) メソッドを経由してのみアクセスすることを
+勧めます。
+これはそれぞれの属性の値を取得または設定するメソッドです。
+既に、前述した C<print_info()> の例で、C<< $self->path >> を
+呼び出しているのを見ています。
 
 =begin original
 
@@ -473,10 +457,10 @@
 
 =end original
 
-You might also see the terms B<getter> and B<setter>. These are two
-types of accessors. A getter gets the attribute's value, while a setter
-sets it. Another term for a setter is B<mutator>
-(TBT)
+B<ゲッター> (getter) と B<セッター> (setter) という用語も見るかも知れません。
+これらはアクセサの種類です。
+ゲッターは属性の値を取得し、セッターは設定します。
+セッターに関する別名は B<ミューテータ> (mutator) です。
 
 =begin original
 
@@ -486,10 +470,9 @@
 
 =end original
 
-Attributes are typically defined as read-only or read-write. Read-only
-attributes can only be set when the object is first created, while
-read-write attributes can be altered at any time.
-(TBT)
+属性は典型的には読み込み専用または読み書き可能として定義されます。
+読み込み専用属性はオブジェクトが最初に作成されるときにのみ設定でき、
+読み書き可能属性はいつでも変更できます。
 
 =begin original
 
@@ -499,10 +482,9 @@
 
 =end original
 
-The value of an attribute may itself be another object. For example,
-instead of returning its last mod time as a number, the C<File> class
-could return a L<DateTime> object representing that value.
-(TBT)
+属性の値それ自身が他のオブジェクトかも知れません。
+例えば、最終更新時刻を数値として返す代わりに、C<File> クラスはその値を
+表現する L<DateTime> オブジェクトを返すかも知れません。
 
 =begin original
 
@@ -511,9 +493,8 @@
 
 =end original
 
-It's possible to have a class that does not expose any publicly
-settable attributes. Not every class has attributes and methods.
-(TBT)
+設定可能な属性が一切公開されていないクラスも可能です。
+全てのクラスが属性とメソッドを持っているというわけではありません。
 
 =head2 Polymorphism
 
@@ -529,12 +510,12 @@
 
 =end original
 
-B<Polymorphism> is a fancy way of saying that objects from two
-different classes share an API. For example, we could have C<File> and
-C<WebPage> classes which both have a C<print_content()> method. This
-method might produce different output for each class, but they share a
-common interface.
-(TBT)
+B<多態性> (polymorphism) は二つの異なるクラスが API を共有しているということを
+示す変わった方法です。
+例えば、どちらも C<print_content()> メソッドを持つ、C<File> クラスと
+C<WebPage> クラスを持てます。
+このメソッドはクラスごとに異なった出力を生成するかも知れませんが、共通の
+インターフェースを共有します。
 
 =begin original
 
@@ -545,11 +526,11 @@
 
 =end original
 
-While the two classes may differ in many ways, when it comes to the
-C<print_content()> method, they are the same. This means that we can
-try to call the C<print_content()> method on an object of either class,
-and B<we don't have to know what class the object belongs to!>
-(TBT)
+二つのクラスはいろいろな意味で異なっているかも知れませんが、
+C<print_content()> メソッドを呼び出すときには、これらは同じです。
+これは、どちらのクラスのオブジェクトに対しても C<print_content()> を
+呼び出そうとすることができて、B<オブジェクトがどのクラスに属しているかを
+知る必要がないと言うことです!>
 
 =begin original
 
@@ -557,8 +538,7 @@
 
 =end original
 
-Polymorphism is one of the key concepts of object-oriented design.
-(TBT)
+多態性はオブジェクト指向設計の鍵となる概念の一つです。
 
 =head2 Inheritance
 
@@ -572,10 +552,9 @@
 
 =end original
 
-B<Inheritance> lets you create a specialized version of an existing
-class. Inheritance lets the new class to reuse the methods and
-attributes of another class.
-(TBT)
+B<継承> は既にあるクラスの特殊版を作成できるようにします。
+継承は他のクラスのメソッドと属性を再利用して新しいクラスを
+作成できるようにします。
 
 =begin original
 
@@ -585,10 +564,10 @@
 
 =end original
 
-For example, we could create an C<File::MP3> class which B<inherits>
-from C<File>. An C<File::MP3> B<is-a> I<more specific> type of C<File>.
-All mp3 files are files, but not all files are mp3 files.
-(TBT)
+例えば、C<File> から B<継承> した C<File::MP3> クラスを作成できます。
+C<File::MP3> B<は> (is-a) C<File> の I<より特殊な> 型です。
+全ての mp3 ファイルはファイルですが、全てのファイルが
+mp3 ファイルというわけではありません。.
 
 =begin original
 
@@ -598,10 +577,9 @@
 
 =end original
 
-We often refer to inheritance relationships as B<parent-child> or
-C<superclass/subclass> relationships. Sometimes we say that the child
-has an B<is-a> relationship with its parent class.
-(TBT)
+継承関係はしばしば B<親-子> または C<スーパークラス/サブクラス> 関係として
+参照されます。
+子は親クラスとの B<is-a> 関係を持つと表現することがあります。
 
 =begin original
 
@@ -610,9 +588,8 @@
 
 =end original
 
-C<File> is a B<superclass> of C<File::MP3>, and C<File::MP3> is a
-B<subclass> of C<File>.
-(TBT)
+C<File> は C<File::MP3> の B<スーパークラス> で、C<File::MP3> は C<File> の
+B<サブクラス> です。
 
   package File::MP3;
 
@@ -625,9 +602,7 @@
 
 =end original
 
-The L<parent> module is one of several ways that Perl lets you define
-inheritance relationships.
-(TBT)
+L<parent> モジュールは、Perl で継承関係を定義するいくつかの方法のひとつです。
 
 =begin original
 
@@ -638,11 +613,10 @@
 
 =end original
 
-Perl allows multiple inheritance, which means that a class can inherit
-from multiple parents. While this is possible, we strongly recommend
-against it. Generally, you can use B<roles> to do everything you can do
-with multiple inheritance, but in a cleaner way.
-(TBT)
+Perl は多重継承を認めています; つまり、クラスは複数の親から継承できます。
+これは可能ですが、行わないように強く勧めます。
+一般的に、多重継承で行えることは全て、B<ロール> を使うことでより
+きれいな形で行えます。
 
 =begin original
 
@@ -653,11 +627,12 @@
 
 =end original
 
-Note that there's nothing wrong with defining multiple subclasses of a
-given class. This is both common and safe. For example, we might define
-C<File::MP3::FixedBitrate> and C<File::MP3::VariableBitrate> classes to
-distinguish between different types of mp3 file.
-(TBT)
+あるクラスに対して複数のサブクラスを定義することは何も悪くないことに
+注意してください。
+これは一般的でかつ安全です。
+例えば、mp3 ファイルの異なった種類を区別するために、
+C<File::MP3::FixedBitrate> クラスと C<File::MP3::VariableBitrate> クラスを
+定義できます。
 
 =head3 Overriding methods and method resolution
 
@@ -673,12 +648,12 @@
 
 =end original
 
-Inheritance allows two classes to share code. By default, every method
-in the parent class is also available in the child. The child can
-explicitly B<override> a parent's method to provide its own
-implementation. For example, if we have an C<File::MP3> object, it has
-the C<print_info()> method from C<File>:
-(TBT)
+継承は二つのクラスでコードを共有できるようにします。
+デフォルトでは、親クラスの全てのメソッドは子でも利用可能です。
+子は、独自の実装を提供することで親のメソッドを明示的に B<オーバーライド>
+(override) できます。
+例えば、C<File::MP3> オブジェクトがあれば、C<File> からの
+C<print_info()> メソッドがあります:
 
   my $cage = File::MP3->new(
       path          => 'mp3s/My-Body-Is-a-Cage.mp3',
@@ -697,9 +672,7 @@
 
 =end original
 
-If we wanted to include the mp3's title in the greeting, we could
-override the method:
-(TBT)
+返り値に mp3 のタイトルを含めたい場合、メソッドをオーバーライドできます:
 
   package File::MP3;
 
@@ -728,14 +701,15 @@
 
 =end original
 
-The process of determining what method should be used is called
-B<method resolution>. What Perl does is look at the object's class
-first (C<File::MP3> in this case). If that class defines the method,
-then that class's version of the method is called. If not, Perl looks
-at each parent class in turn. For C<File::MP3>, its only parent is
-C<File>. If C<File::MP3> does not define the method, but C<File> does,
-then Perl calls the method in C<File>.
-(TBT)
+どのメソッドが使われるべきかを決定する処理は、B<メソッド解決>
+(method resolution) と呼ばれます。
+Perl が行うことは、まずオブジェクトのクラス (この場合は C<File::MP3>) を
+見ます。
+このクラスにメソッドが定義されていれば、そのクラスのメソッドが呼び出されます。
+さもなければ、Perl は順番に親クラスを見ます。
+C<File::MP3> の場合、唯一の親は C<File> です。
+C<File::MP3> がメソッドを定義しておらず、C<File> が定義しているなら、
+Perl は C<File> のメソッドを呼び出します。
 
 =begin original
 
@@ -744,9 +718,8 @@
 
 =end original
 
-If C<File> inherited from C<DataSource>, which inherited from C<Thing>,
-then Perl would keep looking "up the chain" if necessary.
-(TBT)
+C<File> が C<DataSource> から継承され、これが C<Thing> から継承されていれば、
+Perl はもし必要なら「チェーンをたどって」探し続けます。
 
 =begin original
 
@@ -754,8 +727,7 @@
 
 =end original
 
-It is possible to explicitly call a parent method from a child:
-(TBT)
+子から親メソッドを明示的に呼び出すことは可能です:
 
   package File::MP3;
 
@@ -776,10 +748,10 @@
 
 =end original
 
-The C<SUPER::> bit tells Perl to look for the C<print_info()> in the
-C<File::MP3> class's inheritance chain. When it finds the parent class
-that implements this method, the method is called.
-(TBT)
+C<SUPER::> は、C<File::MP3> クラスの継承チェーンから C<print_info()> を
+探すように Perl に伝えます。
+このメソッドを実装している親クラスが見つかると、そのメソッドが
+呼び出されます。
 
 =begin original
 
@@ -789,10 +761,9 @@
 
 =end original
 
-We mentioned multiple inheritance earlier. The main problem with
-multiple inheritance is that it greatly complicates method resolution.
-See L<perlobj> for more details.
-(TBT)
+以前に多重継承について述べました。
+多重継承の主な問題は、メソッド解決が非常に込み入っているということです。
+さらなる詳細については L<perlobj> を参照してください。
 
 =head2 Encapsulation
 
@@ -806,10 +777,9 @@
 
 =end original
 
-B<Encapsulation> is the idea that an object is opaque. When another
-developer uses your class, they don't need to know I<how> it is
-implemented, they just need to know I<what> it does.
-(TBT)
+B<カプセル化> は、オブジェクトを不透明にする考え方です。
+他の開発者があなたのクラスを使うとき、I<どのように> 実装されているかを
+知る必要はなく、単に I<何を> するかを知る必要があるだけです。
 
 =begin original
 
@@ -819,10 +789,9 @@
 
 =end original
 
-Encapsulation is important for several reasons. First, it allows you to
-separate the public API from the private implementation. This means you
-can change that implementation without breaking the API.
-(TBT)
+カプセル化はいくつかの理由で重要です。
+まず、これにより公的な API を内部の実装から分離できます。
+これにより、API を壊すことなく実装を変更できます。
 
 =begin original
 
@@ -834,12 +803,11 @@
 
 =end original
 
-Second, when classes are well encapsulated, they become easier to
-subclass. Ideally, a subclass uses the same APIs to access object data
-that its parent class uses. In reality, subclassing sometimes involves
-violating encapsulation, but a good API can minimize the need to do
-this.
-(TBT)
+次に、クラスが十分にカプセル化されていれば、サブクラス化が容易になります。
+理想的には、サブクラスは親クラスが使っているオブジェクトデータに
+アクセスするのに同じ API を使います。
+実際には、サブクラス化は時々カプセル化に違反しますが、よい API は
+その必要性を最小限にします。
 
 =begin original
 
@@ -852,13 +820,13 @@
 
 =end original
 
-We mentioned earlier that most Perl objects are implemented as hashes
-under the hood. The principle of encapsulation tells us that we should
-not rely on this. Instead, we should use accessor methods to access the
-data in that hash. The object systems that we recommend below all
-automate the generation of accessor methods. If you use one of them,
-you should never have to access the object as a hash directly.
-(TBT)
+既に、ほとんどの Perl オブジェクトは内部ではハッシュとして実装されていると
+述べました。
+カプセル化の原則は、このことに依存するべきではないと伝えています。
+代わりに、ハッシュのデータにアクセスするためにアクセサメソッドを使います。
+後に推奨するオブジェクトシステムは全てアクセサメソッドの生成を自動化します。
+これらの一つを使うなら、オブジェクトをハッシュとして直接アクセスする必要は
+ないはずです。
 
 =head2 Composition
 
@@ -872,10 +840,9 @@
 
 =end original
 
-In object-oriented code, we often find that one object references
-another object. This is called B<composition>, or a B<has-a>
-relationship.
-(TBT)
+オブジェクト指向のコードでは、しばしばあるオブジェクトが他のオブジェクトを
+参照しています。
+これは B<包含> (composition)、または B<has-a> 関係と呼ばれます。
 
 =begin original
 
@@ -887,12 +854,12 @@
 
 =end original
 
-Earlier, we mentioned that the C<File> class's C<last_mod_time>
-accessor could return a L<DateTime> object. This is a perfect example
-of composition. We could go even further, and make the C<path> and
-C<content> accessors return objects as well. The C<File> class would
-then be B<composed> of several other objects.
-(TBT)
+既に、C<File> クラスの C<last_mod_time> アクセサが L<DateTime> オブジェクトを
+返すかも知れないことに触れました。
+これは包含の完璧な例です。
+さらに進めて、C<path> と C<content> アクセサもオブジェクトを返すようにも
+できます。
+そして C<File> クラスはいくつかのその他のオブジェクトの B<包含> になります。
 
 =head2 Roles
 
@@ -907,11 +874,10 @@
 
 =end original
 
-B<Roles> are something that a class I<does>, rather than something that
-it I<is>. Roles are relatively new to Perl, but have become rather
-popular. Roles are B<applied> to classes. Sometimes we say that classes
-B<consume> roles.
-(TBT)
+B<ロール> は、クラスが I<何か> ではなく、クラスが I<何をするか> です。
+ロールは Perl では比較的新しいですが、かなり人気になってきています。
+ロールはクラスに B<適用> されます。
+クラスがロールを B<消費> (consume) するということもあります。
 
 =begin original
 
@@ -922,11 +888,10 @@
 
 =end original
 
-Roles are an alternative to inheritance for providing polymorphism.
-Let's assume we have two classes, C<Radio> and C<Computer>. Both of
-these things have on/off switches. We want to model that in our class
-definitions.
-(TBT)
+ロールは多態性を提供するための継承の代替策です。
+二つのクラス C<Radio> と C<Computer> があると考えます。
+どちらもオン/オフするスイッチがあります。
+これをクラス定義でモデル化したいとします。
 
 =begin original
 
@@ -938,12 +903,12 @@
 
 =end original
 
-We could have both classes inherit from a common parent, like
-C<Machine>, but not all machines have on/off switches. We could create
-a parent class called C<HasOnOffSwitch>, but that is very artificial.
-Radios and computers are not specializations of this parent. This
-parent is really a rather ridiculous creation.
-(TBT)
+C<Machine> のように、共通の親から両方のクラスを継承することもできますが、
+全ての機会にオン/オフスイッチがあるわけではありません。
+C<HasOnOffSwitch> と呼ばれる親クラスを作ることもできますが、とても
+不自然です。
+ラジオとコンピュータはこの親の特殊化ではありません。
+この親は実際にはかなりおかしなものです。
 
 =begin original
 
@@ -954,11 +919,11 @@
 
 =end original
 
-This is where roles come in. It makes a lot of sense to create a
-C<HasOnOffSwitch> role and apply it to both classes. This role would
-define a known API like providing C<turn_on()> and C<turn_off()>
-methods.
-(TBT)
+これはロールの出番です。
+C<HasOnOffSwitch> ロールを作って両方のクラスに適用することは
+とても合理的です。
+このロールは C<turn_on()> と C<turn_off()> メソッドを提供するような
+既知の API を定義します。
 
 =begin original
 
@@ -968,10 +933,9 @@
 
 =end original
 
-Perl does not have any built-in way to express roles. In the past,
-people just bit the bullet and used multiple inheritance. Nowadays,
-there are several good choices on CPAN for using roles.
-(TBT)
+Perl にはロールを記述する組み込みの方法はありません。
+以前は、人々は我慢して多重継承を使っていました。
+最近は、ロールを使うためのいくつかの良い選択肢が CPAN にあります。
 
 =head2 When to Use OO
 
@@ -986,11 +950,10 @@
 
 =end original
 
-Object Orientation is not the best solution to every problem. In I<Perl
-Best Practices> (copyright 2004, Published by O'Reilly Media, Inc.),
-Damian Conway provides a list of criteria to use when deciding if OO is
-the right fit for your problem:
-(TBT)
+オブジェクト指向は全ての問題に対する最良の解法というわけではありません。
+I<Perl Best Practices> (copyright 2004, Published by O'Reilly Media, Inc.)
+において、Damian Conway は OO が問題に正しく適応するかどうかを決定するときに
+使う基準の一覧を提供しています:
 
 =over 4
 
@@ -1002,8 +965,7 @@
 
 =end original
 
-The system being designed is large, or is likely to become large.
-(TBT)
+設計しているシステムが大きいか、大きくなりそう。
 
 =item *
 
@@ -1014,9 +976,7 @@
 
 =end original
 
-The data can be aggregated into obvious structures, especially if
-there's a large amount of data in each aggregate.
-(TBT)
+データが明らかな構造に集合できる; 特にそれぞれの集合が大量のデータを持つ。
 
 =item *
 
@@ -1027,9 +987,7 @@
 
 =end original
 
-The various types of data aggregate form a natural hierarchy that
-facilitates the use of inheritance and polymorphism.
-(TBT)
+様々な型のデータ集合が、継承と多態性を使うことが容易な自然な階層を形成する。
 
 =item *
 
@@ -1040,9 +998,7 @@
 
 =end original
 
-You have a piece of data on which many different operations are
-applied.
-(TBT)
+多くの異なった操作を適用するデータがある。
 
 =item *
 
@@ -1054,10 +1010,8 @@
 
 =end original
 
-You need to perform the same general operations on related types of
-data, but with slight variations depending on the specific type of data
-the operations are applied to.
-(TBT)
+データの種類に関係する同じ一般的な操作をする必要があるが、操作を適用する
+データの特定の種類に依存して少しずつ変化がある。
 
 =item *
 
@@ -1067,8 +1021,7 @@
 
 =end original
 
-It's likely you'll have to add new data types later.
-(TBT)
+後で新しいデータ型を追加する必要がありそう。
 
 =item *
 
@@ -1079,9 +1032,7 @@
 
 =end original
 
-The typical interactions between pieces of data are best represented by
-operators.
-(TBT)
+データ間の典型的な相互作用は演算子によって最もよく表現される。
 
 =item *
 
@@ -1092,9 +1043,7 @@
 
 =end original
 
-The implementation of individual components of the system is likely to
-change over time.
-(TBT)
+システムの独立した要素の実装が時間につれて変化しそう。
 
 =item *
 
@@ -1104,8 +1053,7 @@
 
 =end original
 
-The system design is already object-oriented.
-(TBT)
+システムの設計が既にオブジェクト指向である。
 
 =item *
 
@@ -1115,8 +1063,7 @@
 
 =end original
 
-Large numbers of other programmers will be using your code modules.
-(TBT)
+多くのプログラマがこのコードモジュールを使う。
 
 =back
 
@@ -1841,7 +1788,7 @@
 =begin meta
 
 Translate: SHIRAKATA Kentaro <argra****@ub32*****> (5.16.1-)
-Status: in progress
+Status: completed
 
 =end meta
 



perldocjp-cvs メーリングリストの案内
Back to archive index