Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: OO Identity Crisis

by biosysadmin (Deacon)
on Jun 20, 2005 at 14:27 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-20 04:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found