Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

use of Object oriented program in perl

by gautam_9jan (Initiate)
on Mar 07, 2011 at 10:31 UTC ( [id://891786]=perlquestion: print w/replies, xml ) Need Help??

gautam_9jan has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: use of Object oriented program in perl
by GrandFather (Saint) on Mar 07, 2011 at 11:00 UTC

    In general OO programming is a different way of thinking about organising code and data. In procedural programming the code is in a sense primary with the focus on the algorithm. In OO programming the focus tends more to be on the data. An object is really a ball of data. A class describes the things that can be done to the data contained in an object.

    I very often use OO techniques in small programs to save passing extra parameters around or to avoid using global variables. When writing modules OO techniques provide a number of advantages. OO:

    • avoids pollution of the module user's name space by removing the need for exports.
    • reduces the need for the module user to know about data storage and management within the module.
    • allows the module user to alter or add to the behaviour provided by the module.

    and so on. OO doesn't remove the utility of modules which are a way of organising code into libraries that can be reused. Nor does OO do away with subroutines, but it does change their role somewhat.

    True laziness is hard work
Re: use of Object oriented program in perl
by marto (Cardinal) on Mar 07, 2011 at 10:40 UTC
Re: use of Object oriented program in perl
by Anonymous Monk on Mar 07, 2011 at 10:42 UTC
Re: use of Object oriented program in perl
by chromatic (Archbishop) on Mar 07, 2011 at 19:09 UTC
    ... still we have package and subroutine...

    Perl 5 borrowed its object system from Python and took the approach that class and method are merely syntactic sugar for underlying operations that the runtime translates to symbol table lookups and function invocations anyway.

    Even with that in mind, sometimes we write in higher level languages such as Perl to communicate our ideas to ourselves and other humans and not primarily to the computer. (Sometimes abstractions are nice.)

Re: use of Object oriented program in perl
by pemungkah (Priest) on Mar 10, 2011 at 08:28 UTC
    Hi! I think you're asking "why do we bother with object-oriented programming anyway?"

    Objects let you bind data and behavior together in a way that permits the caller to not care at all what particular piece of code is being executed. As long as the object conforms to the API that the caller expects, the contents of the object and the way in which it does things are of no interest at all to the calling program.

    This leads to programs that are much easier to write and test, and which are much less tightly bound together. Brad Cox, the inventor of Objective-C, called them "software ICs" and that's a good way to start thinking about objects. As long as the connections are what's expected and the outputs match, it doesn't matter which IC you use.

    Objects give us a way to do this with software, making it a lot more reusable and dependable.

      software investment capital, now there is an idear

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://891786]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-03-28 15:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found