Page 2 of 2
Posted: Sat Jan 21, 2006 1:22 am
by feyd
I have no idea if it was the best route to take, however I personally dislike having multiple classes to perform the same operation on differing targets. It just feels cluttered to me.. but we're kinda wondering a bit off topic so I'll shut up unless the original poster would like for this conversation to continue (although I'm basically out of words at this point

)
Posted: Sat Jan 21, 2006 9:38 am
by jonathant
I'm enjoying reading you guys debate. Unfortunately, I don't have enough experience to give an opinion one way or the other. But, I'm learning a lot from all your comments

Posted: Sat Jan 21, 2006 10:58 am
by Ambush Commander
The idea is to do this:
Code: Select all
//in a plugin file
$wgHasher =& new SHA256();
//$wgHasher =& new SHA512();
//in domain logic
$hash = $wgHasher->hash($text);
All you have to do is change the line in the plugin file, and voila, hashing system changed (of course, you'll still have to deal with old records using old hashes)
Posted: Sat Jan 21, 2006 11:11 am
by Christopher
The question of different interfaces really depends on how the code around it would use this class. There is not really a right or wrong here. It is the difference between:
Code: Select all
//in a plugin file
$wgHasher =& new SHA256();
//in domain logic
$hash = $wgHasher->hashURL($text);
//$hash = $wgHasher->hashFile($text);
And:
Code: Select all
//in a plugin file
$wgHasher =& new SHA256URL();
//$wgHasher =& new SHA256File();
//in domain logic
$hash = $wgHasher->hash($text);
Posted: Sat Jan 21, 2006 11:40 am
by Ambush Commander
Well, if $text is a URL, I might want to hash the URL, or I might want to hash the location it points to. There is little advantage to polymorphism between two functions that do wildly different things.
Posted: Sat Jan 21, 2006 2:41 pm
by Christopher
Ambush Commander wrote:Well, if $text is a URL, I might want to hash the URL, or I might want to hash the location it points to. There is little advantage to polymorphism between two functions that do wildly different things.
Right. The fact that they do "do wildly different things" would support that they should be different classes. There is a lot of commonality though. But my main point was that if they all have a hash() method that returns a hash, they can be polymorphic with regards to the classes that consume them. I can then refactor related code to be more generic. Again, the way I work may not be the way you work.
Posted: Sun Jan 22, 2006 7:28 pm
by Jenk
Why overly complicate things? Why create an entire object just for a hash?!
Code: Select all
$hash = SHA256::hash($text, 'URL'); //or 'file', or 'string' etc.. if you are wanting to use just one name
Posted: Sun Jan 22, 2006 8:47 pm
by Christopher
Jenk wrote:Why overly complicate things?
I don't think I was proposing complicating things. Though I'm not sure whether you are talking about he call to the class or the class itself.
Jenk wrote:Why create an entire object just for a hash?!
Why not? If you have looked through the code you would note that at least two "entire" objects are created by the static call you posted.