代码之家  ›  专栏  ›  技术社区  ›  TalentTuner

Unity中的单例模式与集装箱控制的LifeTimeManager

  •  2
  • TalentTuner  · 技术社区  · 15 年前

    数据库中的更改

    1-已从IC_ProductFeature表中删除列维度

    2-添加了新的表IC_ProductDimensions以保存产品的不同维度数据。以下是IC_ProductDimensions中使用的不同列的详细说明

    1- DimensionId - This is the primary key in the table and of bigint datatype.
    
    2- UOMID -  (FK) Unit of Measurement ID , this is refrenced from the table iC_ProductUnitOfMeasure.
    
    3- ProductFeatureId : This is referenced column from the iC_ProductFeature table.
    
    4- NumericValue  : This column stores the dimensional value (e.g. if UOM is pound and this column stores 10 than we can say that Weight of product is 10 pound.
    

    3-在IC“ProductUnitOfMeasure”中添加了一列“MeasurementType”。

    4-将productFeatureID的数据类型从varchar(100)更改为bigint。

    数据流

    IC_ProductUnitOfMeasure中的“MeasurementType”将存储为其创建Mesaure单位的度量。

    e.g. let's take a snapshot view of  rows in iC_ProductUnitOfMeasure 
    
    
        UOMID  Abbrivation         MeasurementType         Description 
    
        1              lb          Weight           This UOM is used for measuring weight of the product 
        2              inch.       Width            This UOM is used for measuring width of the product 
        3              meter       Length           This UOM is used for measuring length of the product 
        4              Kg          Weight           This UOM is used for measuring weight  of product  in Kg.
    

    在上面的示例中,我们用关联度量类型标记了每个UOM。

    UOM 1可用于以磅为单位测量产品重量,同样UOM 4可用于以千克为单位测量产品重量。

    加入产品长度为0.5米,产品宽度为50英寸,产品重量为100磅的产品。

    1-在IC_product表中创建一个记录,以存储产品的公共属性。(供应产品ID=ICPR0001)

    2-在IC_ProductFeature中创建一个记录,并存储常见的产品功能,如颜色、尺寸、S/W、H/W功能(如果有)。(假设productFeatureID=1)

    3-在IC_ProductDimension表中创建3条记录,如下所示。

    DimensionID UOMID ProductFeatureId NumericValue 
    1           1     1                100 
    2           2     1                50 
    3           3     1                0.5 
    

    4-在IC_ProductFeatureApplications中添加一条记录(productID=icpr0001,productFeatureID=1)

    查询数据以获得产品ICPR001的不同尺寸值

    select 
    
              product .* , 
              productFeature.* ,
              ( CAST (dimension.NumericValue  as Varchar(100) )+" " + UOM.Abbrivation) as Dimension ,
              dimension.MeasurementType
    
             from 
                    iC_Product product , 
                    iC_ProductFeature productFeature , 
                    iC_ProductFeatureApplicability , 
                    iC_ProductDimesions dimension , 
                    iC_ProductUnitOfMeasure UOM
    
    where
    
     iC_ProductFeatureApplicability.ProductId = product.ProductId  
    
    and 
    
     iC_ProductFeatureApplicability.ProductFeatureId = productFeature.ProductFeatureId 
    
    and 
    
    dimension.ProductFeatureId = productFeature.ProductFeatureId 
    
    and 
    
    dimension.UOMID= UOM.UOMID
    
    and 
    
     product.ProductId = 'ICPR001'        
    
    2 回复  |  直到 14 年前
        1
  •  2
  •   Community Mohan Dere    8 年前

    真正的单例实例只能实例化一次(在某些实现中,每个线程)。

    Unity Lifetime Management只是让Unity始终返回相同实例的一个选项;该实例不太可能实际设计为单实例,因此原则上,您仍然可以手动创建其他实例。

    看看我的答案 this question 关于区别的更多信息。

        2
  •  0
  •   Andrew Hare    15 年前

    单子模式就是模式本身-简单的统一 器具 这种模式存在于多个地方(包括大多数终身管理者)。

    根据定义,单例不能被模拟——它们被设计为只有一个实例。如果使用singleton的代码是通过接口实现的,那么可以模拟类型来实现该接口,但不能模拟singleton本身。

    至于单件模式是否是反模式,我不相信。我认为它经常被过度使用,并且往往被用来代替更好的解决方案。不过,我不认为这是与模式本身背道而驰的标志。

    推荐文章