in reply to (Re:)+ Constructor/Factory Orthodoxy
in thread Constructor/Factory Orthodoxy

Why I should reject a member of Sub_class_of_Frob as not a Frob?

Because it violated the expectation I had that

my $from = new Frob();
would give me a Frob, not something that is a specialization of a Frob. One can argue about whether new warrants that expectation, but precendent across programming lanaguages does lean strongly that way.

Replies are listed 'Best First'.
Re: Re: (Re:)+ Constructor/Factory Orthodoxy
by rir (Vicar) on Feb 26, 2003 at 23:38 UTC
    You are right that common usage in popular OO languages leans that way. As I stated I tend have that expectation myself. However:

    Can an abstract class not have a constructor?

    Should a subtype be able to be substituted for a supertype in any situation?

    Should I be concerning myself with my object's concrete type on the typical constructor call?

    When I consider these questions I wonder about the validity of my initial expectation.

    It depends on what the meaning of the word 'isa' is.

    Regarding:

    my $frob = new Frob();
    I have a greater expectation, in Perl, that Frob() is a routine call returning something here. That bothers me. This seems a very queer, obstrusive, distracting use of extraneous parentheses.

      That's because that should look like my $frob = Frob->new().

      (Before people flame me, Larry has said on many occasions that he wishes he had not introduced the indirect object syntax.)

      ------
      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.