Created
July 31, 2018 13:23
-
-
Save ceskmcfran/c6d1705a4ee61a76723d19e490a71fa1 to your computer and use it in GitHub Desktop.
Wrong use of Open/Closed principle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum BossType | |
{ | |
Good, | |
Bad | |
} | |
public class Boss | |
{ | |
public string Name { get; set; } | |
public double Money { get; set; } | |
public BossType Type { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Service | |
{ | |
public List<Boss> Bosses { get; set; } | |
public void addMoney() | |
{ | |
foreach (var boss in Bosses) | |
{ | |
double newMoney = 0; | |
switch (boss.Type) | |
{ | |
case BossType.Good: | |
newMoney = boss.Money + 100; | |
break; | |
case BossType.Bad: | |
newMoney = boss.Money - 100; | |
break; | |
} | |
boss.Money = newMoney; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment