The R Project SVN R

Rev

Rev 71540 | Rev 72016 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 71540 Rev 72015
Line 717... Line 717...
717
functions as described in the section on \dQuote{Reference Objects}.
717
functions as described in the section on \dQuote{Reference Objects}.
718
}
718
}
719
} %% end of \describe
719
} %% end of \describe
720
} %% end of \section
720
} %% end of \section
721
 
721
 
722
\section{Implementation}{
722
\section{Implementation; Reference Classes as S4 Classe}{
723
Reference classes are implemented as S4 classes with a data part of
723
Reference classes are implemented as S4 classes with a data part of
724
type \code{"environment"}.
724
type \code{"environment"}.
725
Fields correspond to named objects in the environment.
725
Fields correspond to named objects in the environment.
726
A field associated with a function is implemented as an
726
A field associated with a function is implemented as an
727
\link[=bindenv]{active binding}.
727
\link[=bindenv]{active binding}.
Line 739... Line 739...
739
of fields as data within the object.
739
of fields as data within the object.
740
 
740
 
741
A field, say \code{data}, can be accessed generally by an expression
741
A field, say \code{data}, can be accessed generally by an expression
742
of the form \code{x$data} %$}
742
of the form \code{x$data} %$}
743
for any object from the relevant class.
743
for any object from the relevant class.
744
In a method for this class, the field can be accessed by the name
744
In an internal method for this class, the field can be accessed by the name
745
\code{data}.
745
\code{data}.
746
A field that is not locked can be set by an expression of the form
746
A field that is not locked can be set by an expression of the form
747
\code{x$data <- value}.%$
747
\code{x$data <- value}.%$
748
Inside a method, a field can be assigned by an expression of the form
748
Inside an internal method, a field can be assigned by an expression of the form
749
\code{x <<- value}.
749
\code{x <<- value}.
750
Note the \link[=assignOps]{non-local assignment} operator.
750
Note the \link[=assignOps]{non-local assignment} operator.
751
The standard \R interpretation of this operator works to assign it in
751
The standard \R interpretation of this operator works to assign it in
752
the environment of the object.
752
the environment of the object.
753
If the field has an accessor function defined, getting and setting
753
If the field has an accessor function defined, getting and setting
Line 755... Line 755...
755
 
755
 
756
When a method is invoked on an object, the function defining the method is
756
When a method is invoked on an object, the function defining the method is
757
installed in the object's environment, with the same environment as the
757
installed in the object's environment, with the same environment as the
758
environment of the function.
758
environment of the function.
759
 
759
 
-
 
760
Reference classes can have validity methods in the same sense as any
-
 
761
S4 class (see \code{\link{setValidity}}).
-
 
762
Such methods are often a good idea; they will be called by calling
-
 
763
\code{\link{validObject}} and a validity method, if one is defined,
-
 
764
will be called when a reference object is created (from version 3.4 of
-
 
765
\R on).
-
 
766
Just remember that these are S4 methods.  The function will be called
-
 
767
with the \code{object} as its argument.  Fields and methods must be
-
 
768
accessed using \code{$}.%$
-
 
769
 
760
\emph{Note: Slots.} Because of the implementation, new reference classes can inherit from
770
\emph{Note: Slots.} Because of the implementation, new reference classes can inherit from
761
non-reference S4 classes as well as reference classes, and can include
771
non-reference S4 classes as well as reference classes, and can include
762
class-specific slots in the definition.
772
class-specific slots in the definition.
763
This is usually a bad idea, if the slots from the non-reference
773
This is usually a bad idea, if the slots from the non-reference
764
class are thought of as alternatives to fields.
774
class are thought of as alternatives to fields.