Viewing a response to: @woz.software/the-expression-tree-challenge-follow-up-in-c
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; } ... ```
author | woz.software |
---|---|
permlink | re-wozsoftware-the-expression-tree-challenge-follow-up-in-c-20170908t084141169z |
category | programming |
json_metadata | {"tags":["programming"],"app":"steemit/0.1"} |
created | 2017-09-08 08:41:42 |
last_update | 2017-09-08 08:44:33 |
depth | 1 |
children | 0 |
last_payout | 2017-09-15 08:41:42 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 904 |
author_reputation | 2,321,910,395,519 |
root_title | "The expression tree challenge follow up in C#" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 14,231,517 |
net_rshares | 0 |