跟小D每日学口语
上一页 1 ··· 20 21 22 23 24 25 26 27 28 ··· 77 下一页
摘要: 原文叫看《墨攻》理解IOC概念2006年多部贺岁大片以让人应接不暇的频率纷至沓来,其中张之亮的《墨攻》算是比较出彩的一部,讲述了战国时期墨家人革离帮助梁国反抗赵国侵略的个人英雄主义故事,恢宏壮阔,浑雄凝重的历史场面相当震撼。其中有一个场景:当刘德华所饰的墨者革离到达梁国都城下,城上梁国守军问:“来者何人?”,刘德华回答:“墨者革离!”,我们不妨用C#(原文是java,我修改)对这段“城门问对”的场景进行编剧并借由这个例子来理解IoC的内涵。剧本和饰演者耦合MoAttack代表《墨攻》的剧本,cityGetAsk()代表“城门问对”这段剧情,LiuDeHua是具体饰演者刘德华:代码清单1publ 阅读全文
posted @ 2013-01-08 13:32 Danny Chen 阅读(8842) 评论(3) 推荐(9)
摘要: IOC:英文全称:Inversion of Control,中文名称:控制反转,它还有个名字叫依赖注入(Dependency Injection)。作用:将各层的对象以松耦合的方式组织在一起,解耦,各层对象的调用完全面向接口。当系统重构的时候,代码的改写量将大大减少。理解依赖注入: 当一个类的实例需要另一个类的实例协助时,在传统的程序设计过程中,通常有调用者来创建被调用者的实例。然而采用依赖注入的方式,创建被调用者的工作不再由调用者来完成,因此叫控制反转,创建被调用者的实例的工作由IOC容器来完成,然后注入调用者,因此也称为依赖注入。举个有意思的例子(来源于互联网)假如我们要设计一个Girl. 阅读全文
posted @ 2013-01-08 13:30 Danny Chen 阅读(43434) 评论(25) 推荐(23)
摘要: http://www.cnblogs.com/leoo2sk/archive/2009/06/17/1504693.html这篇文章真的非常非常好···绝对值得收藏学习。目录目录1 IGame游戏公司的故事1.1 讨论会1.2 实习生小李的实现方法1.3 架构师的建议1.4 小李的小结2 探究依赖注入2.1 故事的启迪2.2 正式定义依赖注入3 依赖注入那些事儿3.1 依赖注入的类别3.1.1 Setter注入3.1.2 Construtor注入3.1.3 依赖获取3.2 反射与依赖注入3.3 多态的活性与依赖注入3.3.1 多态性的活性3.3.2 不同活性多态性 阅读全文
posted @ 2013-01-08 11:08 Danny Chen 阅读(18421) 评论(5) 推荐(13)
摘要: TheRepository Patternis a common construct to avoid duplication of data access logic throughout our application. This includes direct access to a database, ORM, WCF dataservices, xml files and so on. The sole purpose of the repository is to hide the nitty gritty details of accessing the data. We can 阅读全文
posted @ 2013-01-08 09:34 Danny Chen 阅读(765) 评论(0) 推荐(1)
摘要: ExamplesThe following code example demonstrates the implementation of theIEnumerableinterfaces for a custom collection. In this example,GetEnumeratoris not explicitly called, but it is implemented to support the use offoreach(For Eachin Visual Basic). This code example is part of a larger example fo 阅读全文
posted @ 2013-01-07 09:25 Danny Chen 阅读(260) 评论(0) 推荐(0)
摘要: IntroductionA popular pattern for ORM data access is the Repository pattern. Repositories are currently very popular even in EF for the reasons below:Hide EF from upper layerMake code better testableThe big disadvantage of EF is rigid architecture which can be hardly mocked, so if you want to unit t 阅读全文
posted @ 2013-01-06 16:25 Danny Chen 阅读(323) 评论(0) 推荐(0)
摘要: 大家还记得Entity Framework 4.1/4.3 之一(概念篇)中我介绍过ObjectContext ObjectSet 以及 DBContext 和DBSet的定义。在使用了4.0很长一段时间后,我向4.3进行了过渡,这个过渡的过程中,我认识并使用了 DBContext 和 DBSet 。感觉很不错。下面我通会表格来分别展示一下ObjectContext ObjectSet DBContext DBSet:DbContextAPI feature (DbContext API功能)Relevant EF4feature/class (有关EF4中的功能/类)General purp 阅读全文
posted @ 2013-01-06 11:09 Danny Chen 阅读(670) 评论(0) 推荐(0)
摘要: In a previous article, we saw how toCreate an Entity Framework Model and Use it in Multiple Projects. In this article, we will see how to Add, Update and Delete objects in our conceptual model and push the changes to the underlying database.We will be using the same console application that we creat 阅读全文
posted @ 2013-01-05 16:55 Danny Chen 阅读(795) 评论(0) 推荐(0)
摘要: IEnumerator:提供在普通集合中遍历的接口,有Current,MoveNext(),Reset(),其中Current返回的是object类型。IEnumerable: 暴露一个IEnumerator,支持在普通集合中的遍历。IEnumerator<T>:继承自IEnumerator,有Current属性,返回的是T类型。IEnumerable<T>:继承自IEnumerable,暴露一个IEnumerator<T>,支持在泛型集合中遍历。1. 要使自定义的集合类型支持foreach访问,就要实现IEnumerable接口。2. 在很多地方有讨论为什 阅读全文
posted @ 2012-12-31 15:50 Danny Chen 阅读(1425) 评论(0) 推荐(0)
摘要: using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace MyFirstAttribute{ class Program { static void Main(string[] args) { System.Reflection.MemberInfo info=typeof(TestClass); MyAttribute myAttribute = Attribute.GetCustom... 阅读全文
posted @ 2012-12-31 01:45 Danny Chen 阅读(195) 评论(0) 推荐(0)
上一页 1 ··· 20 21 22 23 24 25 26 27 28 ··· 77 下一页