Open cxlove opened 8 years ago
step1: using inherit and override to provide different duck behaviors
if we add a new kind of duck, we need to override all behaviors. if we add a new behavior, we need to implement in all kinds of ducks
If we use interface for some special behaviors, we also need to implement it in all kinks of ducks.
So the problem is that the duck have some properties for some kinds of ducks is same and others is different.
step 2: separate fly and sound behavior from duck class, implementing behavior using interface
Conclusion:
We can separate the behavior into three types:
Principle:
RT