ホームページ  >  記事  >  バックエンド開発  >  asp.netの組み合わせパターンの例_PHPチュートリアル

asp.netの組み合わせパターンの例_PHPチュートリアル

WBOY
WBOYオリジナル
2016-07-21 15:15:11873ブラウズ

コードをコピーします コードは次のとおりです:

using System.Collections.Generic;
using System.Text;
namespace Test
{
static void Main (string[] args)
{
var customer = 新しい顧客
{
IsActive = true,
LateFees = 100M,
TotalRentNumber = 10
}; Console.ReadKey( ; /
/// AND 操作
///

I仕様 And(I仕様 other);
///
// / 操作なし
/ //

///
パブリック抽象クラスCompositeSpecify :
public abstract bool IsSatisfiedBy(T 候補);
public ISpecific other)
{
return new AndSpecific(this, other); ISpecific Not()
return new NotSpecific(this)
}
///
public クラスAnd仕様 : 複合仕様
プライベートI仕様
パブリックAnd仕様(I仕様 右仕様)
{左仕様 = leftSpecific ;
this.rightSpec = rightSpec
}
public override bool IsSatisfiedBy(T エンティティ)
{
return leftSpecific.IsSatisfiedBy(entity)
}
}
///
///操作なし
///

public class NotSpecific : CompositeSpecific
public NotSpecific
{ this .innerSpec = innerSpec
}
public override bool IsSatisfiedBy(Tentity)
{
return !innerSpec.IsSatisfiedBy(entity)
}
}
///
///数値に達しました
///

public class HasReachedMaxSpec : CompositeSpec
{
returnentity.TotalRentNumber >
// /
///
///

public class CustomerActiveSpecific : CompositeSpec
{
returnentity.IsActive; }
}
///
/// 支払い期限はありますか?
///

public オーバーライド bool IsSatisfiedBy(Customer エンティティ)
{
return エンティティ .LateFees >
}
public クラス Customer
private ISpecificえっ;
パブリック顧客()
{
hasReachedRentalThreshold = new HasReachedMaxSpecific();
customerHasLateFees = new CustomerHasLateFeesSpec();
///
///

public int TotalRentNumber
{
set;
///
///

public bool IsActive {
get;
}
// ;顧客> canRent = customerIsActive.And(hasReachedRentalThreshold.Not()).And(customerHasLateFees.Not());
}

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/326154.html技術記事代制番号如下: システムを使用します。 System.Collections.Generic を使用します。 System.Linq を使用します。 System.Text を使用します。 namespace Test { class Program { static void Main(string[] args) {...
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。