Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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 romping around the Monastery: (5)
As of 2014-09-18 22:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (125 votes), past polls