<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>唐元志的技术博客</title>
    <description></description>
    <link>https://yuanzhitang.github.io/</link>
    <atom:link href="https://yuanzhitang.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Sat, 08 Oct 2022 02:18:29 +0000</pubDate>
    <lastBuildDate>Sat, 08 Oct 2022 02:18:29 +0000</lastBuildDate>
    <generator>Jekyll v3.9.2</generator>
    
      <item>
        <title>SOLID-单一职责原则(SRP)</title>
        <description>
单一职责原则（Single responsibility principle，SRP）是一个简单而直观的原则，但却是SOLID五大原则中最容易被误解的，也是经常违反的一个原则。可能是由于名字的原因，程序员们会想当然的认为这个原则就是指：每个模块都应该只负责一件事，也就是一个类或者模块只负责完成一个职责。我们要设计粒度小，功能单一的类。毕竟要”高内聚、低耦合”嘛！在重构中，我们也确实一致在强调每个函数值完成一个功能，但是这个方面并不是SRP的全部。

Robert C Martin(Bob大叔) 在他的著作 &lt;strong&gt;《敏捷软件开发：原则、实践与模式》&lt;/strong&gt; 中初次将其定义为
&lt;blockquote&gt;
  一个模块应该有且仅有一个变化的原因
A class should have only one reason to change.
&lt;/blockquote&gt;

而20年后，在他的新书 &lt;strong&gt;《架构整洁之道》&lt;/strong&gt;中，其定义变成了
&lt;blockquote&gt;
  一个模块应该对一类且仅对一类行为者（actor）负责
&lt;/blockquote&gt;

</description>
        <pubDate>Sat, 02 Apr 2022 21:54:14 +0000</pubDate>
        <link>https://yuanzhitang.github.io/2022/04/02/solid-single-responsibility-principle/</link>
        <guid isPermaLink="true">https://yuanzhitang.github.io/2022/04/02/solid-single-responsibility-principle/</guid>
        
        <category>C#</category>
        
        <category>.NET</category>
        
        <category>SOLID</category>
        
        <category>SRP</category>
        
        
        <category>Design</category>
        
      </item>
    
      <item>
        <title>SOLID设计原则开篇</title>
        <description>
SOLID原则是一套比较成体系的设计原则。它不仅可以指导我们设计模块，有效帮助我们设计出易维护，好理解且灵活可扩展的软件，也可以减少软件的复杂性。当你在开发新功能时，不至于牵一发而动全身。在软件维护中，也不至于战战兢兢，因为你不会在担心一个改动会影响到其他组件。

它实际上是五个设计原则首字母的缩写，分别是：
&lt;ul&gt;
  &lt;li&gt;单一职责原则（Single responsibility principle，SRP）&lt;/li&gt;
  &lt;li&gt;开放封闭原则（Open–closed principle，OCP）&lt;/li&gt;
  &lt;li&gt;Liskov 替换原则（Liskov substitution principle，LSP）&lt;/li&gt;
  &lt;li&gt;接口隔离原则（Interface segregation principle，ISP）&lt;/li&gt;
  &lt;li&gt;依赖倒置原则（Dependency inversion principle，DIP）&lt;/li&gt;
&lt;/ul&gt;

</description>
        <pubDate>Sat, 05 Mar 2022 18:09:12 +0000</pubDate>
        <link>https://yuanzhitang.github.io/2022/03/05/solid-principle-summary/</link>
        <guid isPermaLink="true">https://yuanzhitang.github.io/2022/03/05/solid-principle-summary/</guid>
        
        <category>C#</category>
        
        <category>.NET</category>
        
        <category>SOLID</category>
        
        
        <category>Design</category>
        
      </item>
    
      <item>
        <title>C# Coding Standard 最佳实践</title>
        <description>
团队中，代码规范是一件很重要的约定，每一个人都应该去遵守，这样才可以写出大家都容易读懂的代码。本文列出了常用的代码标准规范与约定。
主要涵盖：
&lt;ul&gt;
  &lt;li&gt;类名，变量名&lt;/li&gt;
  &lt;li&gt;常量，缩写&lt;/li&gt;
  &lt;li&gt;下划线，类型名&lt;/li&gt;
  &lt;li&gt;接口，文件名&lt;/li&gt;
  &lt;li&gt;命名空间&lt;/li&gt;
  &lt;li&gt;括号，枚举&lt;/li&gt;
&lt;/ul&gt;

</description>
        <pubDate>Thu, 17 Feb 2022 11:45:41 +0000</pubDate>
        <link>https://yuanzhitang.github.io/2022/02/17/csharp-coding-standard-best-practice/</link>
        <guid isPermaLink="true">https://yuanzhitang.github.io/2022/02/17/csharp-coding-standard-best-practice/</guid>
        
        <category>C#</category>
        
        <category>.NET</category>
        
        <category>代码规范</category>
        
        
        <category>.NET</category>
        
      </item>
    
      <item>
        <title>实现Dispose Pattern</title>
        <description>
实现Dispose方法其实主要是用来释放非托管资源(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unmanaged resource&lt;/code&gt;)。而一个类型中如果有嵌套有另一个实现&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IDisposable&lt;/code&gt;接口的实例成员时，通常会级联调用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dispose&lt;/code&gt;方法。当然一个类中如果只使用了托管资源，也是可以实现Dispose方法去尽早释放资源从而释放已经分配的内存，比如清空一个List，Dictionary等。

针对非托管资源，GC并不负责释放，那么有两个途径可以释放它们：
&lt;ul&gt;
  &lt;li&gt;主动调用Dispose去释放非托管资源&lt;/li&gt;
  &lt;li&gt;终结器中调用Dispose方法，类似于C++的析构函数（也不是完全相同，因为析构函数是人为调用，而终结器取决于GC)&lt;/li&gt;
&lt;/ul&gt;

</description>
        <pubDate>Sat, 15 Jan 2022 08:26:31 +0000</pubDate>
        <link>https://yuanzhitang.github.io/2022/01/15/csharp-dispose-pattern/</link>
        <guid isPermaLink="true">https://yuanzhitang.github.io/2022/01/15/csharp-dispose-pattern/</guid>
        
        <category>C#</category>
        
        <category>.NET</category>
        
        <category>Dispose</category>
        
        
        <category>.NET</category>
        
      </item>
    
      <item>
        <title>C#中如何高效的拼接字符串？</title>
        <description>
字符串拼接是一个非常常见的需求，目前C#中也是支持多种方式进行字符串拼接。

常见的方式有：
&lt;ul&gt;
  &lt;li&gt;用+号&lt;/li&gt;
  &lt;li&gt;string.concat&lt;/li&gt;
  &lt;li&gt;StringBuilder&lt;/li&gt;
  &lt;li&gt;$”{string}”&lt;/li&gt;
  &lt;li&gt;string.format&lt;/li&gt;
  &lt;li&gt;string.join&lt;/li&gt;
&lt;/ul&gt;

那么到底应该采用何种方式最佳呢？

</description>
        <pubDate>Wed, 24 Nov 2021 09:11:24 +0000</pubDate>
        <link>https://yuanzhitang.github.io/2021/11/24/csharp-concat-strings/</link>
        <guid isPermaLink="true">https://yuanzhitang.github.io/2021/11/24/csharp-concat-strings/</guid>
        
        <category>C#</category>
        
        <category>.NET</category>
        
        <category>String</category>
        
        
        <category>.NET</category>
        
      </item>
    
      <item>
        <title>.NET 内存分配实例篇</title>
        <description>
C#中类型主要分为引用类型和值类型，通常情况下值类型分配在堆栈（Stack）上，而引用类型则分配在托管堆(Heap）上。

下图列出了C#中的值类型和引用类型。如果想知道一个变量是值类型还是引用类型，可以采用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;variable.GetType().IsValueType&lt;/code&gt;去检测。

下图列出了C#中的核心值类型和引用类型:
&lt;img width=&quot;90%&quot; src=&quot;https://yuanzhitang.github.io/images/csharp-types.png&quot; /&gt;

</description>
        <pubDate>Sat, 21 Aug 2021 14:24:51 +0000</pubDate>
        <link>https://yuanzhitang.github.io/2021/08/21/csharp-memory-management-samples/</link>
        <guid isPermaLink="true">https://yuanzhitang.github.io/2021/08/21/csharp-memory-management-samples/</guid>
        
        <category>C#</category>
        
        <category>.NET</category>
        
        <category>GC</category>
        
        <category>Stack</category>
        
        <category>Heap</category>
        
        
        <category>.NET</category>
        
      </item>
    
      <item>
        <title>.NET 内存管理原理篇</title>
        <description>
.NET CLR 管理了应用程序占用内存的分配和释放，开发人员在开发托管的应用程序是就不用在开发代码去管理内存了。针对内存的管理依赖于垃圾回收机制（Garbage Collection)，分为 标记(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Full Mark&lt;/code&gt;) -&amp;gt; 回收(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sweep&lt;/code&gt;) -&amp;gt; 压缩(&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Compact&lt;/code&gt;）三个阶段，不在使用引用计数的方式了，类似采用GC机制的还有像Java,Node JS, Go 等编程语言。

&lt;img width=&quot;100%&quot; src=&quot;https://yuanzhitang.github.io/images/MemoryUsedByAProcess.png&quot; /&gt;

</description>
        <pubDate>Tue, 10 Aug 2021 10:25:19 +0000</pubDate>
        <link>https://yuanzhitang.github.io/2021/08/10/csharp-memory-management-solution/</link>
        <guid isPermaLink="true">https://yuanzhitang.github.io/2021/08/10/csharp-memory-management-solution/</guid>
        
        <category>C#</category>
        
        <category>.NET</category>
        
        <category>GC</category>
        
        <category>Heap</category>
        
        <category>Memory</category>
        
        
        <category>.NET</category>
        
      </item>
    
      <item>
        <title>采用JSON.NET序列化接口属性</title>
        <description>
当你的对象中的一个属性（&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Property&lt;/code&gt;）是一个接口，这个接口有几个实现的具体类时，如果采用 JSON.NET 进行简单快速的序列化和反序列化呢?

比如这个例子，一个 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Message&lt;/code&gt;, 他的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Header&lt;/code&gt; 是一个接口，同时 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Message&lt;/code&gt; 自己也是一个抽象类，它有两个子类分别是 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HttpMessage&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RpcMessage&lt;/code&gt;.

</description>
        <pubDate>Tue, 25 May 2021 06:27:19 +0000</pubDate>
        <link>https://yuanzhitang.github.io/2021/05/25/csharp-Serializing-Interfaces-With-JSON-Net/</link>
        <guid isPermaLink="true">https://yuanzhitang.github.io/2021/05/25/csharp-Serializing-Interfaces-With-JSON-Net/</guid>
        
        <category>C#</category>
        
        <category>JSON.NET</category>
        
        
        <category>.NET</category>
        
      </item>
    
      <item>
        <title>C# List指定初始容量以提升性能</title>
        <description>
C# List 类型默认的初始容量是 4，如果随着元素的增加，List 内存是采用翻倍的方式去增加系统的容量，这样则会导致内存需要进行 Resizing，那么如果可以预期到最大的容量需求，如何避免 Resizing 带来的性能损耗呢？

本文主要涵一下几个方面：

&lt;ul&gt;
  &lt;li&gt;演示 List 自动扩容&lt;/li&gt;
  &lt;li&gt;List 手动缩容&lt;/li&gt;
  &lt;li&gt;传递初始容量给 List&lt;/li&gt;
  &lt;li&gt;比较默认和指定初始容量（Initial Capacity)的性能差异&lt;/li&gt;
&lt;/ul&gt;

</description>
        <pubDate>Wed, 27 Jan 2021 20:15:26 +0000</pubDate>
        <link>https://yuanzhitang.github.io/2021/01/27/csharp-Improve-List-Performance-using-fixed-capacity/</link>
        <guid isPermaLink="true">https://yuanzhitang.github.io/2021/01/27/csharp-Improve-List-Performance-using-fixed-capacity/</guid>
        
        <category>C#</category>
        
        <category>List</category>
        
        <category>Performance</category>
        
        <category>Benchmark.NET</category>
        
        
        <category>.NET</category>
        
      </item>
    
      <item>
        <title>.NET执行SQL性能优化一： 针对SQL Server批量执行SQL 语句</title>
        <description>
本文介绍了几种如何使用一个SqlCommand执行多条SQL语句的技术。
&lt;ul&gt;
  &lt;li&gt;SqlCommand.ExecuteNonQuery执行多条SQL&lt;/li&gt;
  &lt;li&gt;使用Data Reader执行两个SELECT语句&lt;/li&gt;
  &lt;li&gt;将SqlDataAdapter用于多个SELECT语句&lt;/li&gt;
  &lt;li&gt;执行匿名T-SQL块&lt;/li&gt;
&lt;/ul&gt;

</description>
        <pubDate>Sun, 29 Mar 2020 22:32:55 +0000</pubDate>
        <link>https://yuanzhitang.github.io/2020/03/29/csharp-execute-batch-sql-performance-tuning-1/</link>
        <guid isPermaLink="true">https://yuanzhitang.github.io/2020/03/29/csharp-execute-batch-sql-performance-tuning-1/</guid>
        
        <category>C#</category>
        
        <category>SQL</category>
        
        <category>Batch</category>
        
        
        <category>.NET</category>
        
      </item>
    
  </channel>
</rss>
