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);
            }
  • 相关阅读:
    为DataGrid 写一个 DropDownListColumn
    网页向女友告白和纪念日专用特效
    CentOS6.5 64位站点压力測试工具webbench
    RxJava系列之二 变换类操作符具体解释1
    C语言实现单链表节点的删除(带头结点)
    excel 补全全部空格
    Linux经常使用命令-文件搜索命令-文件搜索命令find
    错误代码: 1045 Access denied for user &#39;skyusers&#39;@&#39;%&#39; (using password: YES)
    Yocto tips (17): Yocto License问题:restricted license not whitelisted in LICENSE_FLAGS_WHITELIST
    二叉树的基本使用
  • 原文地址:https://www.cnblogs.com/tansm/p/350113.html
Copyright © 2011-2022 走看看