打字猴:1.700475658e+09
1700475658 System.out.println(“生产出的房子是这样的……”);
1700475659
1700475660 }
1700475661
1700475662 //虽然是豆腐渣,也是能够销售出去的
1700475663
1700475664 public void beSelled(){
1700475665
1700475666 System.out.println(“生产出的房子卖出去了……”);
1700475667
1700475668 }
1700475669
1700475670 }
1700475671
1700475672 既然是产品类,那肯定有两种行为要存在:被生产和被销售,否则就不能称为产品了。我们再来看iPod产品类,如代码清单29-9所示。
1700475673
1700475674 代码清单29-9 iPod产品
1700475675
1700475676 public class IPod extends Product{
1700475677
1700475678 public void beProducted(){
1700475679
1700475680 System.out.println(“生产出的iPod是这样的……”);
1700475681
1700475682 }
1700475683
1700475684 public void beSelled(){
1700475685
1700475686 System.out.println(“生产出的iPod卖出去了……”);
1700475687
1700475688 }
1700475689
1700475690 }
1700475691
1700475692 产品是由公司生产出来的,我们来看公司Corp抽象类,如代码清单29-10所示。
1700475693
1700475694 代码清单29-10 抽象公司类
1700475695
1700475696 public abstract class Corp{
1700475697
1700475698 //定义一个抽象的产品对象,不知道具体是什么产品
1700475699
1700475700 private Product product;
1700475701
1700475702 //构造函数,由子类定义传递具体的产品进来
1700475703
1700475704 public Corp(Product product){
1700475705
1700475706 this.product=product;
1700475707
[ 上一页 ]  [ :1.700475658e+09 ]  [ 下一页 ]