Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: difference between OOPs in Perl and java

by dHarry (Abbot)
on Jan 21, 2011 at 07:25 UTC ( #883482=note: print w/ replies, xml ) Need Help??


in reply to difference between OOPs in Perl and java

I don't like Perl OO too much, IMHO there are two many ways to do it! If you want to use OO in Perl I suggest to take a look at Moose. There is manual and a cookbook to get you started.

There are big differences, the two languages are completely different. On top of what ikegami said Let me add/clarify something on Inheritance. Perl supports both single and multiple inheritance. In Java multiple inheritance is not supported directly. This was a design decision. Instead Java has the concept of interfaces. According to some multiple inheritance is evil. The standard argument is the "diamond problem":

A / \ B C \ / D

Suppose a virtual method in A is implemented by both B and C. Question: Which one do you get when you instantiate D?

If you use the Java's interfaces it's not a problem, interfaces don't have implementations. If you make A, B, and C all interfaces, then D chooses how to implement the A method. The Java interfaces are a kind-of multiple inheritance but simplified. Having said this if you use abstract base clases with pure virtual functions (I'm thinking more C++ here) there is no reason why you can't use multiple inheritance.

Cheers

Harry


Comment on Re: difference between OOPs in Perl and java
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2014-08-01 23:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (51 votes), past polls