Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2020-09-26 02:29 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (141 votes). Check out past polls.