An example of ASP. _php Instance

Source: Internet
Author: User
Copy CodeThe code is 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
{
///
Is it possible to rent
///
BOOL IsSatisfiedBy (T entity);
///
and operation
///
ISpecification and (ISpecification Other);
///
No action
///
ISpecification Not ();
}
///
Base class
///
Public abstract class Compositespecification : ISpecification
{
public abstract bool IsSatisfiedBy (T candidate);
Public ISpecification and (ISpecification Other)
{
return new Andspecification (This, other);
}
Public ISpecification Not ()
{
return new Notspecification (this);
}
}
///
and operation
///
public class Andspecification : compositespecification
{
Private ISpecification Leftspecification;
Private ISpecification Rightspecification;
Public Andspecification (ISpecification Leftspecification, ISpecification Rightspecification)
{
This.leftspecification = leftspecification;
This.rightspecification = rightspecification;
}
public override bool IsSatisfiedBy (T entity)
{
return Leftspecification.issatisfiedby (Entity) && Rightspecification.issatisfiedby (entity);
}
}
///
No action
///
public class Notspecification : compositespecification
{
Private ISpecification Innerspecification;
Public Notspecification (ISpecification Innerspecification)
{
This.innerspecification = innerspecification;
}
public override bool IsSatisfiedBy (T entity)
{
return!innerspecification.issatisfiedby (entity);
}
}
///
Whether the maximum number of required leases is reached
///
public class Hasreachedmaxspecification:compositespecification
{
public override bool IsSatisfiedBy (Customer entity)
{
return entity. Totalrentnumber > 5;
}
}
///
is activated
///
public class Customeractivespecification:compositespecification
{
public override bool IsSatisfiedBy (Customer entity)
{
return entity. IsActive;
}
}
///
Do you owe a fee
///
public class Customerhaslatefeesspecification:compositespecification
{
public override bool IsSatisfiedBy (Customer entity)
{
return entity. Latefees > 0;
}
}
public class Customer
{
Private ISpecification Hasreachedrentalthreshold;
Private ISpecification customerisactive;
Private ISpecification customerhaslatefees;
Public Customer ()
{
Hasreachedrentalthreshold = new Hasreachedmaxspecification ();
Customerisactive = new Customeractivespecification ();
Customerhaslatefees = new Customerhaslatefeesspecification ();
}
///
//user Rental DVD number
//
public int totalrentnumber
{
get;
Set;
}
///
//The account is activated
//
public bool IsActive
{
get;
Set;
}
///
//user not yet owed fees
//
Public decimal latefees
{
get;
Set;
}
public bool Canrent ()
{
ISpecification canrent = Customerisactive.and (hasreachedren Talthreshold.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.