create account

RE: The expression tree challenge follow up in C# by woz.software

View this thread on: hive.blogpeakd.comecency.com

Viewing a response to: @woz.software/the-expression-tree-challenge-follow-up-in-c

· @woz.software · (edited)
Actually the intermediate Operation abstract does clean it up some more. Basics of that refactor are...

```
public class Operation : Expression 
{
    private Expression _lhs;
    private Expression _rhs;
    
    public Operation(Expression lhs, Expression rhs)
    {
        _lhs = lhs;
        _rhs = rhs;
    }
    
    protected abstract float CalculateResult(float lhs, float rhs);

    public override float Run() => CalculateResult(_lhs.Run(), _rhs.Run());
}

public class Subtract : Operation
{
    public Subtract(Expression lhs, Expression rhs)
        : base(lhs, rhs) {}
    
    protected override float CalculateResult(float lhs, float rhs) 
        => lhs + rhs;
}

public class Multiply : Operation
{
    public Multiply(Expression lhs, Expression rhs)
        : base(lhs, rhs) {}
    
    protected override float CalculateResult(float lhs, float rhs) 
        => lhs * rhs;
}

...
```
properties (22)
authorwoz.software
permlinkre-wozsoftware-the-expression-tree-challenge-follow-up-in-c-20170908t084141169z
categoryprogramming
json_metadata{"tags":["programming"],"app":"steemit/0.1"}
created2017-09-08 08:41:42
last_update2017-09-08 08:44:33
depth1
children0
last_payout2017-09-15 08:41:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length904
author_reputation2,321,910,395,519
root_title"The expression tree challenge follow up in C#"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id14,231,517
net_rshares0