???????????????
???????????? ???????[ 2013/5/27 13:39:02 ] ????????
?????????????????????????????????Part ?????????
?????????·????????PricePolicy???????????м??????????????????????????????????????????????????????????????????????
public class Part {
private PricePolicy pricePolicy;
public void setPricePolicy(PricePolicy policy) {
pricePolicy = policy;
}
public void setPrice(double price) {
pricePolicy.setPrice(price);
}
public double getPrice() {
return pricePolicy.getPrice();
}
}
public class PricePolicy {
private double basePrice;
public void setPrice(double price) {
basePrice = price;
}
public double getPrice() {
return basePrice;
}
}
public class SalePrice extends PricePolicy {
private double discount;
public void setDiscount(double discount) {
this.discount = discount;
}
public double getPrice() {
return basePrice*discount;
}
}
???????????????????????????????????У???“?仯”?????PricePolicy?????檔???????y???????????????????Part???????????????????趨??????????????????????????ConcretePart????????????????л??????????????????“?仯”?????????????????????
??????????????(LSP)
(1) ??Barbar Liskov(?????.????)????????и????????
(2) ?????:????????????T1?????o1???????????T2?????o2???????T1????????г???P?????е????o1????????o2???????P???????б仯?????????T2??????T1????????.
????????????????????????????????????????????????????????????????????????????????????????????.?????????????滻?????????λ????????????????????????????????????????????????????????????1????
(3) ?????????????????
(4) <ī??.С?>???:"????????; ???????????.????(????)?????;????????????."
(5) ???????????????:???????????????ε?????(????"??")??????????????????????
(6) ???????????????У?????????????У???????????????????????A??B?м?й??????????????????????????????????C?????????A??B?????????C??????.?????????????й???γ?????????????????????????????????е?????????????????;?????е??????????????????????.
(7) "??????????(Design By Constract)?????DBC"????????LISKOV??????????????.??????Bertrand Meyer??????????????????:
???DBC??????д???????漲??????????.?????????д????????????????????????????????.????????????????????????????(preconditions)?????????(postconditions)???????.???????????????У???????????????.????????÷??????????????????.??????????????????????е?????(routine)??????????????????????????????滻???????????????????????????????????????滻???????????.
????????????????????????????????????????????????????????????????????????????????????????????棬??????滻????????????????????б仯??
LSP???и??????????е???????????滻??????????λ?????????????????????????????????????????????????????????????μ??????
???棬???????????????????LSP???????LSP?????????????????????е????????????????????????????????????????????A??B??????Υ????LSP??????(???????B??A???й??)?????????????????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11