//References to PetShop specific libraries //PetShop busines entity library using PetShop.BLL;
namespace PetShop.IDAO{ /**////<summary> /// Interface for the Order DAL ///</summary> publicinterface IOrderDAO{ /**////<summary> /// Method to insert an order header ///</summary> ///<param name="order">Business entity representing the order</param> void Insert(Order order);
/**////<summary> /// Reads the order information for a given orderId ///</summary> ///<param name="orderId">Unique identifier for an order</param> ///<returns>Business entity representing the order</returns> Order GetOrder(int orderId); } }
namespace PetShop.IDAO{ /**////<summary> /// Interface for the Inventory DAL ///</summary> publicinterface IInventoryDAO{ /**////<summary> /// Reduces the stock level by the given quantity for items in an order ///</summary> ///<param name="inventory"></param> void TakeStock(Inventory inventory); } }
这个定义了减少库存的操作。 那么,接下来,我们可以来看看实体类
using System; using System.Collections; using PetShop.Helper; using PetShop.IDAO;
namespace PetShop.BLL{ /**////<summary> /// Business entity used to model an order ///</summary> [Serializable] publicclass Order{ // These variables are used to demonstrate the rollback characterisitic // of distributed transactions and would not form part of a production application privateconststring ACID_USER_ID ="ACID"; privateconststring ACID_ERROR_MSG ="ACID test exception thrown for distributed transaction!";
/**////<summary> /// A method to insert a new order into the system /// The orderId will be generated within the method and should not be supplied /// As part of the order creation the inventory will be reduced by the quantity ordered ///</summary> ///<param name="order">All the information about the order</param> privatevoid InsertInTransaction(){
// Call the insert method in the DAL to insert the header this.Status =new OrderStatus();
foreach(CartItem item in LineItems){ item.TakeStock(); }
// As part of the sample application we have created a user // you can tested distributed transactions with // If the order has been created with the user 'Acid', // then throw an exception which will rollback the entire transaction if (this.UserId == ACID_USER_ID) thrownew ApplicationException(ACID_ERROR_MSG); } } }
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return&
在JDK1.5之前的单例实现方式有两种(懒汉式和饿汉式并无设计上的区别故看做一种),两者同是私有构
造器,导出静态成员变量,以便调用者访问。
第一种
package singleton;
public class Singleton {
//导出全局成员
public final static Singleton INSTANCE = new S