Re: Opinions on "new SomeObject" vs. "SomeObject->new()"
From: pkent (pkent77tea_at_yahoo.com.tea)
Date: 10/09/03
- Next message: ed: "Calling parent constructor"
- Previous message: James Willmore: "Re: TCP Listener on Windows XP"
- In reply to: Lack Mr G M: "Re: Opinions on "new SomeObject" vs. "SomeObject->new()""
- Next in thread: Iain Truskett: "Re: Opinions on "new SomeObject" vs. "SomeObject->new()""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 09 Oct 2003 01:15:42 +0100
In article <2003Oct7.184133@ukwit01>, gml4410@ggr.co.uk (Lack Mr G M)
wrote:
> Except that it is actually:
>
> $new_object = new Class;
>
> and you are *not* asking for a new class.
No, but imagine a better example that uses a slightly better name, like
where I have a class representing Employees. To create a new instance of
an employee I can say:
my $scott = new Employee( Password => 'tiger' );
or of course:
my $scott = Employee->new( Password => 'tiger' );
So in that less abstract example I'm not asking for a new _class_, I'm
asking for a new employee, i.e. a new thing of a certain kind. But at
least with perl you can choose the syntax that you prefer, or that makes
most sense in a given application (like the login tokens example you
give) - you probably can't have one hard and fast rule for every single
case.
Also the use of 'new' as a constructor is just a common convention, but
my constructor can be called anything:
my $scott = existing Employee( ID => '211' );
It's probably terrible to suggest that constructors need not be methods
at all, but could in fact be plain routines:
my $scott = Employee::existing( ID => '211' );
# $scott is an object
but you can do it - there are reasons not to do it :-)
P
-- pkent 77 at yahoo dot, er... what's the last bit, oh yes, com Remove the tea to reply
- Next message: ed: "Calling parent constructor"
- Previous message: James Willmore: "Re: TCP Listener on Windows XP"
- In reply to: Lack Mr G M: "Re: Opinions on "new SomeObject" vs. "SomeObject->new()""
- Next in thread: Iain Truskett: "Re: Opinions on "new SomeObject" vs. "SomeObject->new()""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|