您现在的位置: 天极网 > 开发频道 > 爪哇语言简单工厂创立性模式介绍
全文

爪哇语言简单工厂创立性模式介绍

2001-11-14 11:46作者:阎宏出处:yesky责任编辑:方舟

package com.javapatterns.simplefactory;

public interface FruitIF {
 void grow();

 void harvest();

 void plant();

 String color = null;
 String name = null;
}

     代码清单1. 接口FruitIF的源代码。这个接口确定了水果类必备的方法:种植plant(),生长grow(), 以及收获harvest()。

package com.javapatterns.simplefactory;

public class Apple implements FruitIF
{

 public void grow()
 {
  log("Apple is growing...");
 }

 public void harvest()
 {
  log("Apple has been harvested.");
 }

 public void plant()
 {
  log("Apple has been planted.");
 }

 public static void log(String msg)
 {
  System.out.println(msg);
 }

 public int getTreeAge(){ return treeAge; }

 public void setTreeAge(int treeAge){ this.treeAge = treeAge; }

 private int treeAge;
}

     代码清单2. 类Apple的源代码。萍果是多年生木本植物,因此具备树龄treeAge性质。
共8页。 9 7 1 2 3 4 5 6 7 8 8 :

软件资讯·软件下载尽在天极软件

相关搜索:
相关文章及软件
关注此文读者还看过
热门关注
特别推荐
网友关注
软件下载
娱乐下载
驱动下载
文章排行
本周
本月
最近更新
关于我们|About us|网站律师|天极服务|电子杂志|RSS订阅|加入我们|网站地图
TMG
Copyright (C) 1999-2009 Chinabyte.com, All Rights Reserved 版权所有 天极网络
商务联系、网站内容、合作建议:010-82657868
版权声明 在线提交意见反馈 渝ICP证B2-20030003号
经营性网站备案信息 网警备案 中国网站排名
天极传媒:天极网|比特网|IT专家网|IT商网|52PK游戏网|IT分众