正 文

Java设计模式之外观模式研究


www.7dspace.com  更新日期:2005-11-2 4:32:26  七度空间


  Listing1: AccountClass

public class Account {
 String firstName;
 String lastName;
 final String ACCOUNT_DATA_FILE = "AccountData.txt";
 public Account(String fname, String lname) {
  firstName = fname;
  lastName = lname;
 }
 public boolean isValid() {
  /*
  Let's go with simpler validation
  here to keep the example simpler.
  */
  …
  …
 }
 public boolean save() {
  FileUtil futil = new FileUtil();
  String dataLine = getLastName() + ”," + getFirstName();
  return futil.writeToFile(ACCOUNT_DATA_FILE, dataLine,true, true);
 }
 public String getFirstName() {
  return firstName;
 }
 public String getLastName() {
  return lastName;
 }

  Listing2: Address Class

public class Address {
 String address;
 String city;
 String state;
 final String ADDRESS_DATA_FILE = "Address.txt";
 public Address(String add, String cty, String st) {
  address = add;
  city = cty;
  state = st;
 }
 public boolean isValid() {
  /*
  The address validation algorithm
  could be complex in real-world
  applications.
  Let's go with simpler validation
  here to keep the example simpler.
  */
  if (getState().trim().length() < 2)
   return false;
  return true;
 }
 public boolean save() {
  FileUtil futil = new FileUtil();
  String dataLine = getAddress() + ”," + getCity() + ”," + getState();
  return futil.writeToFile(ADDRESS_DATA_FILE, dataLine,true, true);
 }
 public String getAddress() {
  return address;
 }
 public String getCity() {
  return city;
 }
 public String getState() {
  return state;
 }
}

7页,页码:[1] [2] [3] [4] [5] [6] [7] 

上一篇:互联网的巨大威胁 ICMP洪水攻击浅析
下一篇:ADO.NET 2.0批量数据操作和多动态结果集
作者:stoneWindow 翻译  来源:Java研究组织 ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐