网站首页 语言 会计 电脑 医学 资格证 职场 文艺体育 范文

asp.net 组合模式的PHP代码

栏目: 网页设计 / 发布于: / 人气:7.13K

复制代码 代码如下:

asp.net 组合模式的PHP代码

using System;

using ric;

using ;

using ;

namespace Test

{

class Program

{

static void Main(string[] args)

{

var customer = new Customer

{

IsActive = true,

LateFees = 100M,

TotalRentNumber = 10

};

eLine(ent());

Key();

}

}

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)

{

Specification = leftSpecification;

tSpecification = rightSpecification;

}

public override bool IsSatisfiedBy(T entity)

{

return tisfiedBy(entity) && tisfiedBy(entity);

}

}

///

///否操作

///

public class NotSpecification: CompositeSpecification

{

private ISpecificationinnerSpecification;

public NotSpecification(ISpecificationinnerSpecification)

{

rSpecification = innerSpecification;

}

public override bool IsSatisfiedBy(T entity)

{

return !tisfiedBy(entity);

}

}

///

/// 是否达到最大的规定租赁数

///

public class HasReachedMaxSpecification : CompositeSpecification

{

public override bool IsSatisfiedBy(Customer entity)

{

return lRentNumber > 5;

}

}

///

/// 是否激活

///

public class CustomerActiveSpecification : CompositeSpecification

{

public override bool IsSatisfiedBy(Customer entity)

{

return tive;

}

}

///

/// 是否欠费

///

public class CustomerHasLateFeesSpecification : CompositeSpecification

{

public override bool IsSatisfiedBy(Customer entity)

{

return Fees > 0;

}

}

public class Customer

{

private ISpecificationhasReachedRentalThreshold;

private ISpecificationcustomerIsActive;

private ISpecificationcustomerHasLateFees;

public Customer()

{

hasReachedRentalThreshold = new HasReachedMaxSpecification();

customerIsActive = new CustomerActiveSpecification();

customerHasLateFees = new CustomerHasLateFeesSpecification();

}

///

/// 用户租赁DVD数量

///

public int TotalRentNumber

{

get;

set;

}

///

/// 账户是否激活

///

public bool IsActive

{

get;

set;

}

///

/// 用户之前是否还欠费

///

public decimal LateFees

{

get;

set;

}

public bool CanRent()

{

ISpecificationcanRent = (())(());

return tisfiedBy(this);

}

}

}