Re: Opinions on "new SomeObject" vs. "SomeObject->new()"

From: pkent (pkent77tea_at_yahoo.com.tea)
Date: 10/09/03


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


Relevant Pages

  • Re: Factory Class Question
    ... move EmployeeFactory, Employee, Facilty1Employee, and Facilty2Employee all ... Facilty1Employee, and Facilty2Employee as Friend. ... > Facility2_Employee has an overloaded constructor which means I can't make ... >> instance of a class with a private constructor is rare, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Factory Class Question
    ... Jay - thanks for the response. ... I have a base class called Employee ... Facility2_Employee has an overloaded constructor which means I can't make it ... >> Jason MacKenzie ...
    (microsoft.public.dotnet.languages.vb)
  • Re: A simple employee class : OOP Study
    ... > someone might be able to simply outline what I envision my class to look ... > Basically I am envisioning a Class called Employee: ... > I imagine it would have many propertiessuch as: ... > well into business object uses. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: IC v. Employee question
    ... >an employee and after the work relationship ended they filed for ... I imagine you're right. ... Rae Morrill in Maine ... "Ya can't get theyuh from heeah" ...
    (sci.med.transcription)
  • Re: Can this Class be cleaned up at all?
    ... less than 8 significant digits. ... All I need to do is change the way that the initialSalary is defined in the Employee class and the other classes that extend it should be easy to retrofit. ... That means that every class that extends employee and creates a new employee will have to have the call to the constructor changed. ...
    (comp.lang.java.help)