Objective-C#++
Published on
Gaze upon my creation and despair. Witness... Objective-C#++
template<typename T> class BinaryOperationManager : NSObject { IBinaryOperation Operation { get; private set; } T Left { get; private set; } T Right { get; private set; } - (T) performOperation { return [this.Operation performWithLeft:this.Left right:this.Right]; } - (void) setLeftValue:(T)newValue { if (this.Left != nullptr) { throw [System.InvalidOperationException .ctor:"Left value already set"]; } this.Left = newValue; } - (void) setRightValue:(T)newValue { if (this.Right != nullptr) { throw [System.InvalidOperationException .ctor:"Right value already set"]; } this.Right = newValue; } - (instancetype) init:(IBinaryOperation)operation { this.Operation = operation; return this; } + (instancetype) new:(IBinaryOperation)operation { return [[[this class] alloc] init:operation]; } }
Some quick analysis of this... thing now that I've created it...
- Templates. There's nothing else I have to say.
- The use of
nullptr
I guess implies thatNULL
also exists and compares equal to zero here. [System.InvalidOperationException .ctor]
shows that, somehow, this creature is, indeed, meant to be running on the CLR (your named-after-the-class constructor ends up as a static factory method named.ctor
by the time the compiler is done with it, and yes, that's a valid name for a CLR method and you can find it and call it directly via reflection).- Somehow
[[[this class] alloc] init]
is one of the least bad things here. - Such a lovely API design, isn't it?
Tagged:
- Programming
- Evil