随笔分类 -  设计模式

摘要: 阅读全文
posted @ 2020-05-08 09:11 谁说程序猿很猥琐 阅读(81) 评论(0) 推荐(0)
摘要:using System; namespace 原型模式 { class Program { static void Main(string[] args) { // 使用静态构造对象(和单例相似) { System.Diagnostics.Stopwatch stopwatch = new Sys 阅读全文
posted @ 2020-04-12 22:21 谁说程序猿很猥琐 阅读(180) 评论(0) 推荐(0)
摘要:static void Main(string[] args) { /*建造者模式,适合创建复杂对象,与工厂模式的关注点不一样,建造者重点关注,对象过程的创建 * * * */ { // 创建 福特 车 注重每个过程的建造 BuilderFord builder = new BuilderFord( 阅读全文
posted @ 2020-04-12 21:17 谁说程序猿很猥琐 阅读(101) 评论(0) 推荐(0)
摘要:static void Main(string[] args) { Simple simpleOne = new SimpleOne(); simpleOne.ShowName(); Simple simpleTwo = new SimpleTwo(); simpleTwo.ShowName(); 阅读全文
posted @ 2020-04-12 19:33 谁说程序猿很猥琐 阅读(169) 评论(0) 推荐(0)
摘要:对于多线程,线程同时运行GetInstance方法时,此时两个线程判断(uniqueInstance ==null)这个条件时都返回真,此时两个线程就都会创建Singleton的实例,这样就违背了我们单例模式初衷了,既然上面的实现会运行多个线程执行,那我们对于多线程的解决方案自然就是使GetInst 阅读全文
posted @ 2018-06-13 18:10 谁说程序猿很猥琐 阅读(198) 评论(0) 推荐(0)