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);
}
}
}
相關文章
-
PHP生成SiteMap文件的代碼
分享一例php生成sitemap地圖文件的`代碼,用於生成google sitemap地圖,有需要的朋友參考學習下。 生成sitemap文件例子:複製代碼 代碼示例:<?php/*** 生成sitemap文件* 平常在用的一段代碼,分享給大家* edit: */require -
php sitemap文件生成器代碼
本文分享一例php生成sitemap文件的代碼,一個簡單的google sitemap文件生成器代碼,有需要的朋友參考下。就跟隨小編去了解下吧,想了解更多相關信息請 持續關注我們應屆畢業生考試網!php sitemap文件生成器例子:複製代碼 代 -
php自動生成sitemap地圖的代碼
如何生成sitemap地圖呢?本文分享一例php代碼,用於自動動態生成最新的sitemap地圖文件,並通知google網站地圖的更新,感興趣的`朋友參考下吧。 php自動生成sitemap地圖例子,:主要生成sitemap的類。代碼:複製代碼 代碼示例:< -
PHP生成SiteMap文件代碼的方法
分享一例php生成sitemap地圖文件的代碼,用於生成google sitemap地圖,有需要的'朋友參考學習下。例子:複製代碼 代碼示例:<?php/*** 生成sitemap文件* 平常在用的一段代碼,分享給大家* edit: */require_once(''); -
php自動生成sitemap地圖代碼
如何生成sitemap地圖呢?本文分享一例php代碼,用於自動動態生成最新的sitemap地圖文件,並通知google網站地圖的'更新,感興趣的朋友參考下吧。本節內容:php自動生成sitemap地圖例子,:主要生成sitemap的類。代碼:複製代碼 代碼 -
php自動生成sitemap地圖的代碼大綱
如何生成sitemap地圖呢?本文分享一例php代碼,用於自動動態生成最新的`sitemap地圖文件,並通知google網站地圖的更新,感興趣的朋友參考下吧。內容:php自動生成sitemap地圖例子,:主要生成sitemap的類。代碼:複製代碼 代碼示例:< -
php生成sitemap.xml的實例代碼
本文分享一個自己寫的'生成文件的php代碼,感興趣的朋友可以參考下。本節內容:php生成例子:複製代碼 代碼示例:<?PHP/*** 生成文件*/$content='<?xml version="1.0" encoding="UTF-8"?><urlsetxmlns=""xmlns:xsi=""x -
The Best Thing That Could Ever Happen少兒雙語閱讀
Unit 3 The Best Thing That Could Ever Happen單元 3 最棒的事Three old men were sitting around and talking.三個老頭坐在一起聊天。The 80-year-old remarked, "The best thing that could happen to me would j -
php動態生成JavaScript代碼
如何生成javascript的實現代碼,就跟隨本站小編一起去了解下吧,想了解更多相關信息請持續關注我們應屆畢業生考試網!複製代碼 代碼如下:<?phpecho <<<JS //使用多行輸出的方法輸出JavaScript代碼<SCRIPT Language = "Jav -
豌豆上的公主英語作文 The Princess and the Pea
The Princess and the PeaThere was once a prince,who led a happy day his father said to him,"I'm getting I die,you will make a good you need a yourself a wife!"So the prince traveled around the