An example of ASP.net combination mode _php example

Source: Internet
Author: User
Copy Code code as follows:

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<t>
{
<summary>
Whether you can lease
</summary>
BOOL IsSatisfiedBy (T entity);
<summary>
and operation
</summary>
Ispecification<t> and (ispecification<t> other);
<summary>
No action
</summary>
Ispecification<t> not ();
}
<summary>
Base class
</summary>
Public abstract class Compositespecification<t>: ispecification<t>
{
public abstract bool IsSatisfiedBy (T candidate);
Public ispecification<t> and (ispecification<t>)
{
Return to New andspecification<t> (this, other);
}
Public ispecification<t> not ()
{
Return to New notspecification<t> (this);
}
}
<summary>
and operation
</summary>
public class Andspecification<t>: compositespecification<t>
{
Private ispecification<t> leftspecification;
Private ispecification<t> rightspecification;
Public Andspecification (ispecification<t> leftspecification, ispecification<t> rightSpecification)
{
This.leftspecification = leftspecification;
This.rightspecification = rightspecification;
}
public override bool IsSatisfiedBy (T entity)
{
return Leftspecification.issatisfiedby (Entity) && Rightspecification.issatisfiedby (entity);
}
}
<summary>
No action
</summary>
public class Notspecification<t>: compositespecification<t>
{
Private ispecification<t> innerspecification;
Public notspecification (ispecification<t> innerspecification)
{
This.innerspecification = innerspecification;
}
public override bool IsSatisfiedBy (T entity)
{
return!innerspecification.issatisfiedby (entity);
}
}
<summary>
Whether the maximum number of leases is reached
</summary>
public class Hasreachedmaxspecification:compositespecification<customer>
{
public override bool IsSatisfiedBy (Customer entity)
{
return entity. Totalrentnumber > 5;
}
}
<summary>
Whether to activate
</summary>
public class Customeractivespecification:compositespecification<customer>
{
public override bool IsSatisfiedBy (Customer entity)
{
return entity. IsActive;
}
}
<summary>
Whether the fee is owed
</summary>
public class Customerhaslatefeesspecification:compositespecification<customer>
{
public override bool IsSatisfiedBy (Customer entity)
{
return entity. Latefees > 0;
}
}
public class Customer
{
Private ispecification<customer> Hasreachedrentalthreshold;
Private ispecification<customer> customerisactive;
Private ispecification<customer> customerhaslatefees;
Public Customer ()
{
Hasreachedrentalthreshold = new Hasreachedmaxspecification ();
customerisactive = new Customeractivespecification ();
Customerhaslatefees = new Customerhaslatefeesspecification ();
}
<summary>
Number of users renting DVDs
</summary>
public int Totalrentnumber
{
Get
Set
}
<summary>
Whether the account is active
</summary>
public bool IsActive
{
Get
Set
}
<summary>
Whether the user owes a fee before
</summary>
Public decimal Latefees
{
Get
Set
}
public bool Canrent ()
{
ispecification<customer> canrent = Customerisactive.and (Hasreachedrentalthreshold.not ()). and (Customerhaslatefees.not ());
Return Canrent.issatisfiedby (this);
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.