Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Re: Re: perl OO - to use or not to use

by BUU (Prior)
on Sep 14, 2003 at 17:50 UTC ( #291425=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: perl OO - to use or not to use
in thread perl OO - to use or not to use

Wouldn't the example you mentioned be considered OO programming anyways? I mean, it does the exact same thing as 'traditional' OO programming, it just has a slightly different form. Do we have to have a 'class' and then create an 'object' and then call a method on the object by using specialized syntax? Why would this: $obj->meth(); be considered OO and this meth($obj) not be?


Comment on Re: Re: Re: perl OO - to use or not to use
Select or Download Code
Re: Re: Re: Re: perl OO - to use or not to use
by liz (Monsignor) on Sep 14, 2003 at 18:56 UTC
    With OO, the subroutine "meth" could be inherited (exist in another namespace from which the object inherits). When called as a subroutine, the subroutine must exist in the current namespace (or some pretty heavy AUTOLOAD magic should be involved).

    Liz

      Other important difference is that in case of OO syntax caller in general doesn't know how $obj will handle method call (i.e. caller doesn't know which subroutine in which package is going to be called) as it depends on the class of $obj.

      --
      Ilya Martynov, ilya@iponweb.net
      CTO IPonWEB (UK) Ltd
      Quality Perl Programming and Unix Support UK managed @ offshore prices - http://www.iponweb.net
      Personal website - http://martynov.org

Re: Re: Re: Re: perl OO - to use or not to use
by IlyaM (Parson) on Sep 14, 2003 at 19:47 UTC
    First of all I'd like to mention that the syntax is secondary to the design of system. It is possible to express OO design using purely procedural syntax (case in point: first C++ compilers were actually just preprocessors which generated C code they feed to real C compilers). And of course it is quite possible to write purely procedural code using OO syntax.

    The syntax meth($obj) will work as substitution for $obj->meth() until you need data abstraction (i.e. you don't have classes which share same interfaces, particulary your class tree is flat and you don't use inheritance). Some would argue that data abstraction is essential property of OO design and if a system doesn't use data abstraction it is not OO at all.

    --
    Ilya Martynov, ilya@iponweb.net
    CTO IPonWEB (UK) Ltd
    Quality Perl Programming and Unix Support UK managed @ offshore prices - http://www.iponweb.net
    Personal website - http://martynov.org

Re: Re: Re: Re: perl OO - to use or not to use
by signal9 (Pilgrim) on Sep 15, 2003 at 23:24 UTC
    Do we have to have a 'class' and then create an 'object' and then call a method on the object by using specialized syntax?

    Yes, that is exactly the point of object oriented programming. For it to be OO programming, you need to be able to create multiple instances of a class with all attributes and functions implied by that class.

    Your second examples are not analagous. In the case of $obj->meth();, the programmer is calling a method which belongs to the class, or the instance of that class. In the case of meth($obj), the programmer is passing a variable to a function which has no inherent relationship to the variable passed. The examples may look somewhat similar, but they are doing very different things.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://291425]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2014-12-29 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (186 votes), past polls