Athena's blog

Objective-C#++

Athena Lilith Martin

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...

Tagged: