class with only static functions
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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
)
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
The idea is to do this:
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)
Code: Select all
//in a plugin file
$wgHasher =& new SHA256();
//$wgHasher =& new SHA512();
//in domain logic
$hash = $wgHasher->hash($text);- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
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:And:
Code: Select all
//in a plugin file
$wgHasher =& new SHA256();
//in domain logic
$hash = $wgHasher->hashURL($text);
//$hash = $wgHasher->hashFile($text);Code: Select all
//in a plugin file
$wgHasher =& new SHA256URL();
//$wgHasher =& new SHA256File();
//in domain logic
$hash = $wgHasher->hash($text);(#10850)
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
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.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.
(#10850)
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- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
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 overly complicate things?
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.Jenk wrote:Why create an entire object just for a hash?!
(#10850)