From sfalcon at fhcrc.org  Wed Jan 31 16:04:11 2007
From: sfalcon at fhcrc.org (Seth Falcon)
Date: Wed, 31 Jan 2007 07:04:11 -0800
Subject: [Rd] S4 initialize or "generating function"
In-Reply-To: <45BFB590.3080405@TU-Dresden.de> (Thomas Petzoldt's message of
	"Tue, 30 Jan 2007 22:16:00 +0100")
References: <45BFB590.3080405@TU-Dresden.de>
Message-ID: <m2r6tbdyqc.fsf@fhcrc.org>

Thomas Petzoldt <Thomas.Petzoldt at TU-Dresden.de> writes:

> Hello,
>
> apologies if I missed something well known. I'm just revising an own
> package and wonder if it is still common to use "generating
> functions" which have the same name as the corresponding S4 class as
> suggested by Chambers, 2001. "Classes and Methods in the S Language".
>
> -- or should one consequently use new and initialize to do such
>    things?

If you have no inheritence between the classes in your system (and are
pretty sure you are not going to have any) then I don't think it
really matters whether you define MyClass() to create new instances or
use new("MyClass",...).

There is considerable advantage to having your constructors be real
methods when you do have inheritence relations among your classes.
This allows you to make use of callNextMethod to reduce code
duplication.

Defining an "initialize" method and using new seems to be the standard
and I suspect is required if you want to plug into the validObject
protocol.  The "initialize" setup tries to make some strange
assumptions about how objects should be able to be constructed (IMO) [*1*].
Furthermore, it is a bummer to lose multiple dispatch when defining
constructors.

+ seth


[*1*] The default initialize method interprets named arguments as
slots which is a reasonable default, but not always sensible.  What I
find quite strange is that an un-named argument is interpreted as an
instance that should be cloned.



[Rd] S4 initialize or "generating function"
Seth Falcon