Could be extracted into method and then condition could be replaced by inheritance + method overriding.