zoukankan      html  css  js  c++  java
  • ObjectBuilder 学习笔记

            [TestMethod]
            
    public void CanCreateInstances()                                                    //测试是否能够创建实例
            {
                Builder builder 
    = new Builder();                                                //对象建造器
                Locator locator = CreateLocator();                                              //定位器

                ConstructorPolicy policy 
    = new ConstructorPolicy();                             //建立一个构造策略
                policy.AddParameter(new ValueParameter<int>(12));                               //为策略加入参数
                builder.Policies.Set<ICreationPolicy>(policy, typeof(SimpleObject), null);      //将此策略加入建造器

                SimpleObject m1 
    = builder.BuildUp<SimpleObject>(locator, nullnull);           //建造对象
                SimpleObject m2 = builder.BuildUp<SimpleObject>(locator, nullnull);

                Assert.IsNotNull(m1);
                Assert.IsNotNull(m2);
                Assert.AreEqual(
    12, m1.IntParam);
                Assert.AreEqual(
    12, m2.IntParam);
                Assert.IsTrue(m1 
    != m2);
            }

            [TestMethod]
            
    public void CanCreateSingleton()
            
    {
                Builder builder 
    = new Builder();
                Locator locator 
    = CreateLocator();

                ConstructorPolicy policy 
    = new ConstructorPolicy();
                policy.AddParameter(
    new ValueParameter<int>(12));
                builder.Policies.Set
    <ICreationPolicy>(policy, typeof(SimpleObject), null);
                
    //为SimpleObject添加单实例策略。
                builder.Policies.Set<ISingletonPolicy>(new SingletonPolicy(true), typeof(SimpleObject), null);  

                SimpleObject m1 
    = builder.BuildUp<SimpleObject>(locator, nullnull);
                SimpleObject m2 
    = builder.BuildUp<SimpleObject>(locator, nullnull);

                Assert.AreSame(m1, m2);
            }
  • 相关阅读:
    [leetcode] #279 Perfect Squares (medium)
    vue-cli3.0配置详解
    babel7 的配置加载逻辑
    webpack-小滴课堂学习笔记
    VUE-cli3使用 svg-sprite-loader
    打包报错,提示UglifyJs Unexpected token: keyword «const»
    UglifyJs报Unexpected token punc «:», expected punc «,» 这类错误的解决办法
    element-ui实现部分引用
    图解 HTTP 缓存
    process.argv
  • 原文地址:https://www.cnblogs.com/tansm/p/350113.html
Copyright © 2011-2022 走看看