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

Re: OO Identity Crisis

by biosysadmin (Deacon)
on Jun 20, 2005 at 14:27 UTC ( #468370=note: print w/ replies, xml ) Need Help??


in reply to OO Identity Crisis

In my Java classes at school this question came up when dealing with Java collections. Very often a data structure will need to enforce some sort of uniqueness, but there's no way for the data structure designer to know how to compare two objects.

The way Java deals with this is to make the client class provide a comparison method. So, in your example, the Node class should be able to do the following:

if ( $node1->isEqual( $node2 ) ) { print "The two nodes are the same!\n"; }
That's a simple and easy way to prevent duplicates without making your Tree class do more than it should.


Comment on Re: OO Identity Crisis
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2014-12-19 21:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (92 votes), past polls