亚洲精品中文字幕无乱码_久久亚洲精品无码AV大片_最新国产免费Av网址_国产精品3级片

ASP

asp.net 組合模式的PHP代碼

時間:2024-08-31 20:26:51 ASP 我要投稿
  • 相關(guān)推薦

asp.net 組合模式的PHP代碼

  復制代碼 代碼如下:

  using System;

  using System.Collections.Generic;

  using System.Linq;

  using System.Text;

  namespace Test

  {

  class Program

  {

  static void Main(string[] args)

  {

  var customer = new Customer

  {

  IsActive = true,

  LateFees = 100M,

  TotalRentNumber = 10

  };

  Console.WriteLine(customer.CanRent());

  Console.ReadKey();

  }

  }

  public interface ISpecification

  {

  ///

  /// 是否可以租賃

  ///

  bool IsSatisfiedBy(T entity);

  ///

  /// 與操作

  ///

  ISpecificationAnd(ISpecificationother);

  ///

  /// 否操作

  ///

  ISpecificationNot();

  }

  ///

  /// 基類

  ///

  public abstract class CompositeSpecification: ISpecification

  {

  public abstract bool IsSatisfiedBy(T candidate);

  public ISpecificationAnd(ISpecificationother)

  {

  return new AndSpecification(this, other);

  }

  public ISpecificationNot()

  {

  return new NotSpecification(this);

  }

  }

  ///

  /// 與操作

  ///

  public class AndSpecification: CompositeSpecification

  {

  private ISpecificationleftSpecification;

  private ISpecificationrightSpecification;

  public AndSpecification(ISpecificationleftSpecification, ISpecificationrightSpecification)

  {

  this.leftSpecification = leftSpecification;

  this.rightSpecification = rightSpecification;

  }

  public override bool IsSatisfiedBy(T entity)

  {

  return leftSpecification.IsSatisfiedBy(entity) && rightSpecification.IsSatisfiedBy(entity);

  }

  }

  ///

  ///否操作

  ///

  public class NotSpecification: CompositeSpecification

  {

  private ISpecificationinnerSpecification;

  public NotSpecification(ISpecificationinnerSpecification)

  {

  this.innerSpecification = innerSpecification;

  }

  public override bool IsSatisfiedBy(T entity)

  {

  return !innerSpecification.IsSatisfiedBy(entity);

  }

  }

  ///

  /// 是否達到最大的規(guī)定租賃數(shù)

  ///

  public class HasReachedMaxSpecification : CompositeSpecification

  {

  public override bool IsSatisfiedBy(Customer entity)

  {

  return entity.TotalRentNumber > 5;

  }

  }

  ///

  /// 是否激活

  ///

  public class CustomerActiveSpecification : CompositeSpecification

  {

  public override bool IsSatisfiedBy(Customer entity)

  {

  return entity.IsActive;

  }

  }

  ///

  /// 是否欠費

  ///

  public class CustomerHasLateFeesSpecification : CompositeSpecification

  {

  public override bool IsSatisfiedBy(Customer entity)

  {

  return entity.LateFees > 0;

  }

  }

  public class Customer

  {

  private ISpecificationhasReachedRentalThreshold;

  private ISpecificationcustomerIsActive;

  private ISpecificationcustomerHasLateFees;

  public Customer()

  {

  hasReachedRentalThreshold = new HasReachedMaxSpecification();

  customerIsActive = new CustomerActiveSpecification();

  customerHasLateFees = new CustomerHasLateFeesSpecification();

  }

  ///

  /// 用戶租賃DVD數(shù)量

  ///

  public int TotalRentNumber

  {

  get;

  set;

  }

  ///

  /// 賬戶是否激活

  ///

  public bool IsActive

  {

  get;

  set;

  }

  ///

  /// 用戶之前是否還欠費

  ///

  public decimal LateFees

  {

  get;

  set;

  }

  public bool CanRent()

  {

  ISpecificationcanRent = customerIsActive.And(hasReachedRentalThreshold.Not()).And(customerHasLateFees.Not());

  return canRent.IsSatisfiedBy(this);

  }

  }

  }

【asp.net 組合模式的PHP代碼】相關(guān)文章:

數(shù)控編程代碼大全02-13

php實習心得12-01

php實習報告11-07

Java代碼的基本知識09-03

php工作總結(jié)11-11

php是什么格式?01-14

PHP Socket編程過程02-09

php開發(fā)主管的職責05-15

網(wǎng)頁滾動文字的制作HTML代碼04-10

php開發(fā)主管的工作職責09-29