Skip to content

Commit f05537c

Browse files
authored
Create 3_LSP_code_refactor.md
1 parent c640b1c commit f05537c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

3_LSP_code_refactor.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
> Based on the problem with Ostriches trying to fly, we should consider removing Fly from our base Bird class
2+
3+
class Bird { }
4+
5+
class FlyingBird {
6+
void Fly() { return "fly"; }
7+
}
8+
9+
class Dove : FlyingBird {
10+
void Fly() { return "flap"; }
11+
}
12+
class Eagle : FlyingBird {
13+
void Fly() { return "soar"; }
14+
}
15+
class Ostrich : Bird { }
16+
17+
> Now we can make all flying birds, fly:
18+
19+
this.flyingBirds = new List<FlyingBird>();
20+
this.flyingBirds.Add(new Dove());
21+
this.flyingBirds.Add(new Eagle());
22+
23+
foreach(var flyingBird in this.flyingBirds) {
24+
flyingBird.Fly(); //success!
25+
}
26+
27+
[&laquo; back to readme.md](README.md)

0 commit comments

Comments
 (0)