| Line 1... |
Line 1... |
| 1 |
% File src/library/methods/man/stdRefClass.Rd
|
1 |
[% File src/library/methods/man/stdRefClass.Rd
|
| 2 |
% Part of the R package, http://www.R-project.org
|
2 |
% Part of the R package, http://www.R-project.org
|
| 3 |
% Copyright 2010-2 R Core Team
|
3 |
% Copyright 2010-2 R Core Team
|
| 4 |
% Distributed under GPL 2 or later
|
4 |
% Distributed under GPL 2 or later
|
| 5 |
|
5 |
|
| 6 |
\name{envRefClass-class}
|
6 |
\name{envRefClass-class}
|
| Line 28... |
Line 28... |
| 28 |
This class implements basic reference-style semantics for \R{}
|
28 |
This class implements basic reference-style semantics for \R{}
|
| 29 |
objects. Objects normally do not come directly from this class, but
|
29 |
objects. Objects normally do not come directly from this class, but
|
| 30 |
from subclasses defined by a call to \code{\link{setRefClass}}.
|
30 |
from subclasses defined by a call to \code{\link{setRefClass}}.
|
| 31 |
The documentation below is technical background describing the implementation, but applications
|
31 |
The documentation below is technical background describing the implementation, but applications
|
| 32 |
should use the interface documented under \code{\link{setRefClass}},
|
32 |
should use the interface documented under \code{\link{setRefClass}},
|
| 33 |
in particular the \code{\$} operator and field accessor functions as
|
33 |
in particular the \code{$} operator and field accessor functions as
|
| 34 |
described there.
|
34 |
described there.
|
| 35 |
}
|
35 |
}
|
| 36 |
|
36 |
|
| 37 |
\section{A Basic Reference Class}{
|
37 |
\section{A Basic Reference Class}{
|
| 38 |
The design of reference classes for \R{} divides those classes up
|
38 |
The design of reference classes for \R{} divides those classes up
|
| Line 40... |
Line 40... |
| 40 |
and class methods.
|
40 |
and class methods.
|
| 41 |
Each version of this mechanism is defined by a \emph{basic reference
|
41 |
Each version of this mechanism is defined by a \emph{basic reference
|
| 42 |
class}, which must implement a set of methods and provide some
|
42 |
class}, which must implement a set of methods and provide some
|
| 43 |
further information used by \code{\link{setRefClass}}.
|
43 |
further information used by \code{\link{setRefClass}}.
|
| 44 |
|
44 |
|
| 45 |
The required methods are for operators \code{\$} and \code{\$<-} to
|
45 |
The required methods are for operators \code{$} and \code{$<-} to
|
| 46 |
get and set a field in an object, and for \code{\link{initialize}} to
|
46 |
get and set a field in an object, and for \code{\link{initialize}} to
|
| 47 |
initialize objects.
|
47 |
initialize objects.
|
| 48 |
|
48 |
|
| 49 |
To support these methods, the basic reference class needs to have some
|
49 |
To support these methods, the basic reference class needs to have some
|
| 50 |
implementation mechanism to store and retrieve data from fields in the
|
50 |
implementation mechanism to store and retrieve data from fields in the
|
| Line 58... |
Line 58... |
| 58 |
objects.
|
58 |
objects.
|
| 59 |
Other basic reference classes may use an interface to a language such
|
59 |
Other basic reference classes may use an interface to a language such
|
| 60 |
as Java or C++ using reference semantics for classes.
|
60 |
as Java or C++ using reference semantics for classes.
|
| 61 |
|
61 |
|
| 62 |
Usually, the \R user will be able to invoke class methods on the
|
62 |
Usually, the \R user will be able to invoke class methods on the
|
| 63 |
class, using the \code{\$} operator. The basic reference class
|
63 |
class, using the \code{$} operator. The basic reference class
|
| 64 |
method for \code{\$} needs to make this possible. Essentially, the
|
64 |
method for \code{$} needs to make this possible. Essentially, the
|
| 65 |
operator must return an \R function corresponding to the object and
|
65 |
operator must return an \R function corresponding to the object and
|
| 66 |
the class method name.
|
66 |
the class method name.
|
| 67 |
|
67 |
|
| 68 |
Class methods may include an implementation of data abstraction, in
|
68 |
Class methods may include an implementation of data abstraction, in
|
| 69 |
the sense that fields are accessed by \dQuote{get} and \dQuote{set}
|
69 |
the sense that fields are accessed by \dQuote{get} and \dQuote{set}
|