正 文

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


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



  Listing3: CreditCard Class

public class CreditCard {
 String cardType;
 String cardNumber;
 String cardExpDate;
 final String CC_DATA_FILE = "CC.txt";
 public CreditCard(String ccType, String ccNumber,
 String ccExpDate) {
  cardType = ccType;
  cardNumber = ccNumber;
  cardExpDate = ccExpDate;
 }
 public boolean isValid() {
  /*
  Let's go with simpler validation
  here to keep the example simpler.
  */
  if (getCardType().equals(AccountManager.VISA)) {
   return (getCardNumber().trim().length() == 16);
  }
  if (getCardType().equals(AccountManager.DISCOVER)) {
   return (getCardNumber().trim().length() == 15);
  }
  if (getCardType().equals(AccountManager.MASTER)) {
   return (getCardNumber().trim().length() == 16);
  }
  return false;
 }
 public boolean save() {
  FileUtil futil = new FileUtil();
  String dataLine = getCardType() + ,”" + getCardNumber() + ”," + getCardExpDate();
  return futil.writeToFile(CC_DATA_FILE, dataLine, true, true);
 }
 public String getCardType() {
  return cardType;
 }
 public String getCardNumber() {
  return cardNumber;
 }
 public String getCardExpDate() {
  return cardExpDate;
 }
}


Figure3: Subsystem Classes to Provide the Necessary Functionality to Validate and Save the Customer Data
7页,页码:[1] [2] [3] [4] [5] [6] [7] 

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

热 点 导 读
特 别 推 荐