FAQ
Hi list,

I'm using some design patterns (MVC, Observer, Strategy), with Perl, however I see that I need to create some interfaces (watching examples in Java and C++), but I don't know how to create these interfaces with Perl, for example in Java this is done with this:

public interface SomeName () {
# some code
}

Is this possible with Perl or is there any other way for do it ???

Regards and thanks to all !!!


--
_______________________________________________
Get your free email from http://bsdmail.com

Search Discussions

  • Chas Owens at Aug 1, 2007 at 6:42 pm

    On 8/1/07, Rafael Morales wrote:
    Hi list,

    I'm using some design patterns (MVC, Observer, Strategy), with Perl, however I see that I need to create some interfaces (watching examples in Java and C++), but I don't know how to create these interfaces with Perl, for example in Java this is done with this:

    public interface SomeName () {
    # some code
    }

    Is this possible with Perl or is there any other way for do it ???

    Regards and thanks to all !!!

    If I remember correctly, interfaces in Java are a hack to get around
    the fact that you can't do multiple inheritance. Perl can do multiple
    inheritance*, so all you need to do is create a new class SomeName and
    have other class inherites from it (the base pragma is the easiest
    way).

    * whether this is a good or bad thing depends on how likely you are to
    run into diamond inheritance, and the other problems multiple
    inheritance can cause.
  • Paul Lalli at Aug 1, 2007 at 7:23 pm

    On Aug 1, 2:20 pm, darede...@bsdmail.com (Rafael Morales) wrote:

    I'm using some design patterns (MVC, Observer, Strategy), with Perl,
    however I see that I need to create some interfaces (watching examples
    in Java and C++), but I don't know how to create these interfaces with
    Perl, for example in Java this is done with this:

    public interface SomeName () {
    # some code
    }

    Is this possible with Perl or is there any other way for do it ???
    For those of us who are Java-ignorant (and mostly proud of it),
    perhaps you could describe what it is you actually want to do, rather
    than just telling us how you would do it in another language.

    "Interface" as a generic word means something completely different
    than it means as a Java keyword, and I don't at all remember from the
    one semester of Java I took 7 years ago what that meaning is.

    Paul Lalli
  • Octavian Rasnita at Aug 2, 2007 at 5:23 am
    An interface is a kind of "contract" that need to be respected by all the
    classes that implement that interface.
    All those classes should have the methods specified by the interface and
    those methods should have the same signature (they are able to receive the
    same parameters types).

    Perl is not a strongly typed language, and the subroutines in perl can
    receive any number of parameters and they can be of any type.

    In perl, the program don't enforce any type checking, but the programmer
    must do it.
    If the programmer wants to be sure that one of his classes respects some
    rules, define some methods of a certain type, and so on, then he should make
    the program in that way. If he doesn't do it, the program won't give an
    error telling that he doesn't respect the "contract".

    Sometimes this is an advantage, and sometimes it is not...

    Octavian

    ----- Original Message -----
    From: "Paul Lalli" <mritty@gmail.com>
    To: <beginners@perl.org>
    Sent: Wednesday, August 01, 2007 10:22 PM
    Subject: Re: Programming an interface with Perl

    On Aug 1, 2:20 pm, darede...@bsdmail.com (Rafael Morales) wrote:

    I'm using some design patterns (MVC, Observer, Strategy), with Perl,
    however I see that I need to create some interfaces (watching examples
    in Java and C++), but I don't know how to create these interfaces with
    Perl, for example in Java this is done with this:

    public interface SomeName () {
    # some code
    }

    Is this possible with Perl or is there any other way for do it ???
    For those of us who are Java-ignorant (and mostly proud of it),
    perhaps you could describe what it is you actually want to do, rather
    than just telling us how you would do it in another language.

    "Interface" as a generic word means something completely different
    than it means as a Java keyword, and I don't at all remember from the
    one semester of Java I took 7 years ago what that meaning is.

    Paul Lalli


    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    http://learn.perl.org/
  • Rafael Morales at Aug 1, 2007 at 10:36 pm
    OK, this is for a MVC implementation, but all examples I have seen are done with Java or C++, even php5 which uses the same
    keyword "interface", and this interface is a way for comunicate between classes.



    ----- Original Message -----
    From: "Paul Lalli" <mritty@gmail.com>
    To: beginners@perl.org
    Subject: Re: Programming an interface with Perl
    Date: Wed, 01 Aug 2007 12:22:44 -0700

    On Aug 1, 2:20 pm, darede...@bsdmail.com (Rafael Morales) wrote:

    I'm using some design patterns (MVC, Observer, Strategy), with Perl,
    however I see that I need to create some interfaces (watching examples
    in Java and C++), but I don't know how to create these interfaces with
    Perl, for example in Java this is done with this:

    public interface SomeName () {
    # some code
    }

    Is this possible with Perl or is there any other way for do it ???
    For those of us who are Java-ignorant (and mostly proud of it),
    perhaps you could describe what it is you actually want to do, rather
    than just telling us how you would do it in another language.

    "Interface" as a generic word means something completely different
    than it means as a Java keyword, and I don't at all remember from the
    one semester of Java I took 7 years ago what that meaning is.

    Paul Lalli


    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
    http://learn.perl.org/
    >


    --
    _______________________________________________
    Get your free email from http://bsdmail.com
  • Paul Lalli at Aug 2, 2007 at 12:12 am

    On Aug 1, 6:25 pm, darede...@bsdmail.com (Rafael Morales) wrote:
    OK, this is for a MVC implementation, but all examples I have seen are done with Java or C++, even php5 which uses the same
    keyword "interface", and this interface is a way for comunicate between classes.
    Do you know what it is you *ACTUALLY* want to do? How do you want to
    communicate between classes? What is it about Perl's object oriented
    system that is preventing you from doing so?

    Give an example, in your existing Perl code, of something that you
    WANT to do, but don't know HOW to do. Don't say "Well in Java or C+
    +, I'd program an interface", say what is the actual problem you're
    looking to solve.

    My guess is that you're just assuming you can't do something without
    actually attempting to do it. Perl is insanely free-form in
    comparison to other languages. Especially the object-oriented
    aspects. There is rarely a need for the workarounds you have to
    create in other languages.

    Paul
  • Rob Dixon at Aug 2, 2007 at 12:30 am

    Rafael Morales wrote:

    I'm using some design patterns (MVC, Observer, Strategy), with Perl,
    however I see that I need to create some interfaces (watching
    examples in Java and C++), but I don't know how to create these
    interfaces with Perl, for example in Java this is done with this:

    public interface SomeName () { # some code }

    Is this possible with Perl or is there any other way for do it ???
    In a Perl class, all methods are public and the calling code isn't
    checked at compile time to make sure a method exists. So there is no
    need for an 'interface' in the ways that Java defines it.

    HTH,

    Rob

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedAug 1, '07 at 6:32p
activeAug 2, '07 at 5:23a
posts7
users5
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase