The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
15357 jmc 1
\name{Classes}
2
\alias{Classes}
16802 jmc 3
\alias{__ClassMetaData}
15357 jmc 4
\title{Class Definitions}
5
\description{
19029 hornik 6
  Class definitions are objects that contain the formal definition of a
7
  class of R objects.
15357 jmc 8
}
9
\details{
19029 hornik 10
  When a class is defined, an object is stored that contains the
11
  information about that class, including:
15357 jmc 12
 
19029 hornik 13
  \describe{
14
    \item{slots}{Each slot is a component object.  Like elements of a
15
      list these may be extracted (by name) and set.  However, they
16
      differ from list components in important ways.
15357 jmc 17
 
19029 hornik 18
      All the objects from a particular class have the same set of slot
19
      names; specifically, the slot names that are contained in the
20
      class definition.  Each slot in each object always has the same
21
      class; again, this is defined by the overall class definition.
15357 jmc 22
 
19029 hornik 23
      Classes don't need to have any slots, and many useful classes do
24
      not.  These objects usually extend other, simple objects, such as
25
      numeric or character vectors.  Finally, classes can have no data
26
      at all---these are known as \emph{virtual} classes and are in fact
27
      very important programming tools.  They are used to group together
28
      ordinary classes that want to share some programming behavior,
29
      without necessarily restricting how the behavior is implemented.
15357 jmc 30
    }
19029 hornik 31
    \item{extends}{The names of the classes that this class extends.  A
15357 jmc 32
      class \code{Fancy}, say, extends a class \code{Simple} if an
33
      object from the \code{Fancy} class has all the capabilities of
34
      the \code{Simple} class (and probably some more as well).  In
35
      particular, and very usefully, any method defined to work for a
36
      \code{Simple} object can be applied to a \code{Fancy} object as
37
      well.
38
 
39
      In other programming languages, this relationship is sometimes
40
      expressed by saying that \code{Simple} is a superclass of
41
      \code{Fancy}, or that \code{Fancy} is a subclass of
42
      \code{Simple}.
43
 
44
      The actual class definition object contains the names of all the
45
      classes this class extends.  But those classes can themselves
46
      extend other classes also, so the complete extension can only be
47
      known by obtaining all those class definitions.
48
 
49
      Class extension is usually defined when the class itself is
50
      defined, by including the names of superclasses as unnamed
51
      elements in the representation argument to \code{\link{setClass}}.
52
 
53
      An object from a given class will then have all the slots
54
      defined for its own class \emph{and} all the slots defined for
55
      its superclasses as well.
56
 
57
      Note that \code{extends} relations can be defined in other ways
58
      as well, by using the \code{\link{setIs}} function.
19029 hornik 59
    }
15357 jmc 60
    \item{prototype}{Each class definition contains a prototype object
19029 hornik 61
      from the class.  This must have all the slots, if any, defined by
62
      the class definition.
15357 jmc 63
 
19029 hornik 64
      The prototype most commonly just consists of the prototypes of all
65
      its slots.  But that need not be the case:  the definition of the
66
      class can specify any valid object for any of the slots.
15357 jmc 67
 
25118 hornik 68
      There are a number of \dQuote{basic} classes, corresponding to the
19029 hornik 69
      ordinary kinds of data occurring in R.  For example,
70
      \code{"numeric"} is a class corresponding to numeric vectors.
71
      These classes are predefined and can then be used as slots or as
72
      superclasses for any other class definitions.  The prototypes for
73
      the vector classes are vectors of length 0 of the corresponding
74
      type.
15357 jmc 75
 
19029 hornik 76
      There are also a few basic virtual classes, the most important
77
      being \code{"vector"}, grouping together all the vector classes;
78
      and \code{"language"}, grouping together all the types of objects
79
      making up the R language.
80
    }
81
  }
15357 jmc 82
}
83
\references{
19029 hornik 84
  The web page \url{http://www.omegahat.org/RSMethods/index.html} is the
85
  primary documentation.
15357 jmc 86
 
19029 hornik 87
  The functions in this package emulate the facility for classes and
88
  methods described in \emph{Programming with Data} (John M. Chambers,
89
  Springer, 1998).  See this book for further details and examples.
15357 jmc 90
}
91
\author{
92
  John Chambers
93
}
19029 hornik 94
\seealso{
95
  \code{\link{Methods}},
96
  \code{\link{setClass}},
97
  \code{\link{is}},
98
  \code{\link{as}},
99
  \code{\link{new}},
100
  \code{\link{slot}}
101
}
15357 jmc 102
\keyword{programming}
103
\keyword{classes}
104
\keyword{methods}