• <sub id="h4knl"><ol id="h4knl"></ol></sub>
    <sup id="h4knl"></sup>
      <sub id="h4knl"></sub>

      <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
      1. <strong id="h4knl"></strong>

      2. asp.net 組合模式的PHP代碼

        時(shí)間:2024-10-07 12:35:26 ASP 我要投稿
        • 相關(guān)推薦

        asp.net 組合模式的PHP代碼

          復(fù)制代碼 代碼如下:

          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);

          }

          }

          ///

          /// 是否達(dá)到最大的規(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;

          }

          }

          ///

          /// 是否欠費(fèi)

          ///

          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;

          }

          ///

          /// 用戶之前是否還欠費(fèi)

          ///

          public decimal LateFees

          {

          get;

          set;

          }

          public bool CanRent()

          {

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

          return canRent.IsSatisfiedBy(this);

          }

          }

          }

        《&.doc》
        将本文的Word文档下载到电脑,方便收藏和打印
        推荐度:
        点击下载文档

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

        php數(shù)組函數(shù)序列之a(chǎn)rray-combine() - 數(shù)組合并函數(shù)的代碼08-25

        php如何過(guò)濾危險(xiǎn)html代碼09-21

        將php實(shí)現(xiàn)過(guò)濾UBB代碼09-11

        php對(duì)圖像的各種處理函數(shù)代碼總結(jié)07-03

        如何在cmd下面寫php代碼01-22

        ASP.NET連SQL7接口的源代碼06-06

        PHP url 加密解密函數(shù)代碼方法10-25

        企業(yè)薪酬設(shè)計(jì)基本模式及組合模式02-26

        關(guān)于PHP var-dump遍歷對(duì)象屬性的函數(shù)與應(yīng)用代碼06-21

        關(guān)于ASP.NET使用JavaScript顯示信息提示窗口實(shí)現(xiàn)原理及代碼05-09

        在线咨询
        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码
      3. <sub id="h4knl"><ol id="h4knl"></ol></sub>
        <sup id="h4knl"></sup>
          <sub id="h4knl"></sub>

          <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
          1. <strong id="h4knl"></strong>

          2. 夜色福利院在线观看免费 | 亚洲欧洲日韩综合一区在线 | 亚洲综合中文字幕在线一区 | 亚洲一区在线精品 | 亚洲国产精品日韩AV专区 | 日本免费特黄欧美片 |

            asp.net 組合模式的PHP代碼

              復(fù)制代碼 代碼如下:

              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);

              }

              }

              ///

              /// 是否達(dá)到最大的規(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;

              }

              }

              ///

              /// 是否欠費(fèi)

              ///

              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;

              }

              ///

              /// 用戶之前是否還欠費(fèi)

              ///

              public decimal LateFees

              {

              get;

              set;

              }

              public bool CanRent()

              {

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

              return canRent.IsSatisfiedBy(this);

              }

              }

              }