日期:2009-07-18 浏览次数:20375 次
public class Customer { // 私有数据成员 String _customerId; String _companyName; String _contactName; String _contactTitle; public Customer() {} // Customer对象的属性 public String CustomerId { get { return _customerId; } set { _customerId = value;} } public String CompanyName { get { return _companyName; } set { _companyName = value;} } public String ContactName { get { return _contactName; } set { _contactName = value;} } public String ContactTitle { get { return _contactTitle; } set { _contactTitle = value;} } } public interface ICustomerFactory { // 用于单行操作的标准事务方法 void Load(Customer cust); void Insert(Customer cust); void Update(Customer cust); void Delete(Customer cust); // 返回集合的查询方法 ArrayList FindCustomersByState(String state); } public class CustomerFactory : ICustomerFactory { //用于单行操作的标准事务方法 void Load(Customer cust) { /* Implement here */ } void Insert(Customer cust) { /* Implement here */ } void Update(Customer cust) { /* Implement here */ } void Delete(Customer cust) { /* Implement here */ } //返回集合的查询方法 ArrayList FindCustomersByState(String state) { /* 此处是实现代码 */ } } |
public class NorthwindApp { static void Main (string[] args) { Customer cust = new Customer(); CustomerFactory custFactory = new CustomerFactory(); //从Northwind数据库载入客户 cust.CustomerId = "ALFKI"; custFactory.load(cust); // 传递 Customer 对象 FooBar(cust); // custList是Customer对象列表 ArrayList custList = custFactory.FindCustomersByState("CA"); } } |