惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Webroot Blog
Webroot Blog
U
Unit 42
A
About on SuperTechFans
宝玉的分享
宝玉的分享
月光博客
月光博客
C
CERT Recently Published Vulnerability Notes
P
Privacy International News Feed
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
P
Privacy & Cybersecurity Law Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
Securelist
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Spread Privacy
Spread Privacy
L
Lohrmann on Cybersecurity
Apple Machine Learning Research
Apple Machine Learning Research
K
Kaspersky official blog
Hugging Face - Blog
Hugging Face - Blog
B
Blog
I
Intezer
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
V
V2EX
L
LangChain Blog
AI
AI
G
GRAHAM CLULEY
T
Tor Project blog
人人都是产品经理
人人都是产品经理
D
Docker
WordPress大学
WordPress大学
Google DeepMind News
Google DeepMind News
I
InfoQ
Y
Y Combinator Blog
C
Comments on: Blog
GbyAI
GbyAI
www.infosecurity-magazine.com
www.infosecurity-magazine.com
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
H
Help Net Security
Vercel News
Vercel News
T
Tenable Blog
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿

博客园 - 网络金领

C# WinForm 导出导入Excel/Doc 完整实例教程[使用Aspose.Cells.dll] DataTable的数据批量写入数据库 C# .NET锁屏程序(顺带屏蔽任务管理器) 步步为营 .NET 代码重构学习 十一 - 网络金领 步步为营 .NET 代码重构学习笔记 十 步步为营 .NET 代码重构学习笔记 九 步步为营 .NET 代码重构学习笔记 七 步步为营 .NET 代码重构学习笔记 六、移动函数和移动值域(Move Method And Move Field) 步步为营 .NET 代码重构学习笔记 五、分解函数和替换算法(Replace Method And Substitute Algorithm) 步步为营 .NET 代码重构学习笔记 四、临时变量(Temporary Variable) 步步为营 .NET 代码重构学习笔记 二、提炼方法(Extract Method) 步步为营 .NET 代码重构学习笔记 三、内联方法(Inline Method) 步步为营 .NET 代码重构学习笔记 一、为何要代码重构 步步为营 .NET 设计模式学习笔记 二十四、Factory Method(工厂方法模式) 步步为营 .NET 设计模式学习笔记 二十三、Interpreter(解释器模式) 步步为营 .NET 设计模式学习笔记 二十二、Memento(备望录模式) 步步为营 .NET 设计模式学习笔记 二十一、Visitor(访问者模式) 步步为营 .NET 设计模式学习笔记 二十、Mediator(中介者模式) 步步为营 .NET 设计模式学习笔记 十九、Chain of Responsibility(职责链模式)
步步为营 .NET 代码重构学习笔记 八
网络金领 · 2011-06-02 · via 博客园 - 网络金领

一、Introduce Foreign Method(引入外加函数)

动机(Motivation)

在client class 中建立一个函数,并以一个server class实体作为第一引数(argument)。

示例

1 DateTime newStart = DateTime.Now.AddDays(1);

改为

1 public DateTime  NextDate()
3     return  DateTime.Now.AddDays(1);

二、Introduce Local Extension(引入本地扩展)

动机(Motivation)

建立一个新class,使它包含这些额外函数。让这个扩展品成为source class的subclass(子类)或wrapper(外覆类)。

示例

03     Computer _computer;
04     StringBuilder strCom = new StringBuilder();
05     strCom.AppendLine("你的电脑配置如下:");
06     strCom.AppendLine("主板是:" + _computer.MainBoard());
07     strCom.AppendLine("处理器是:" + _computer.Cpu());
08     strCom.AppendLine("显卡是:" + _computer.PhenoType());
09     strCom.AppendLine("内存是:" + _computer.Memory());
10     strCom.AppendLine("硬盘是:" + _computer.HardDisk());
11     strCom.AppendLine("显示器是:" + _computer.Display());
12     strCom.AppendLine("己组装完成");
13     Console.WriteLine(strCom.ToString);

改为

03          Console.WriteLine(ShowComputerConfigure());
06      public string ShowComputerConfigure()
08          Computer _computer;
09          StringBuilder strCom = new StringBuilder();
10          strCom.AppendLine("你的电脑配置如下:");
11          strCom.AppendLine("主板是:" + _computer.MainBoard());
12          strCom.AppendLine("处理器是:" + _computer.Cpu());
13          strCom.AppendLine("显卡是:" + _computer.PhenoType());
14          strCom.AppendLine("内存是:" + _computer.Memory());
15          strCom.AppendLine("硬盘是:" + _computer.HardDisk());
16          strCom.AppendLine("显示器是:" + _computer.Display());
17          strCom.AppendLine("己组装完成");
19          return strCom.ToString();

三、Self Encapsulate Field(自封装值域)

动机(Motivation)

为这个值域建立取值/设置函数(getting/setting methods),并且只以这些函数来访问值域。

示例

1 public  int _low, _high;
2 public bool Includes(int arg)
4     return arg >= _low && arg <= _high;

改为

01 private int _low, _high;
05     get { return _low; }
06     set { _low = value; }
11     get { return _high; }
12     set { _high = value; }
15 public bool Includes(int arg)
17     return arg >= Low && arg <= High;

四、Replace Data Value with Object(以对象取代数据值)

动机(Motivation)

将数据项变成一个对象

示例

3     private string _name;
6         get { return _name; }
7         set { _name = value; }

改为

03     private string _name;
04     public string Name
06         get { return _name; }
07         set { _name = value; }
09     public Customer(string name)
11         this._name = name;

引用时

1 string name = new Customer("spring yang");

五、Change Value to Referencce(将实值对象改为引用对象)

动机(Motivation)

将value object(实值对象)变成一个reference object(引用对象)

示例

1 public void GetCustomers()
3     string[] UserName = { new Customer("Spring Yang"), new Customer("Lemon Car"), new Customer("Associated Coffee") };

改为

01 private Dictionary<string, Customer> dicUserName = new Dictionary<string, Customer>();
03        public void GetCustomers()
05            string[] UserName = { dicUserName.TryGetValue("Spring Yang"), dicUserName.TryGetValue("Lemon Car"),
06                                    dicUserName.TryGetValue("Associated Coffee") };
09        private void LoadCustomers()
11            AddCustomer("Spring Yang");
12            AddCustomer("Lemon Car");
13            AddCustomer("Associated Coffee");
16        private void AddCustomer(string name)
18            dicUserName.Add(name, new Customer(name));

六、Change Reference to Value(将引用对象改为实值对象)

动机(Motivation)

reference object(引用对象),很小且不可变(immutable),而且不易管理。

示例

01 private Dictionary<string, Customer> dicUserName = new Dictionary<string, Customer>();
03        public void GetCustomers()
05            string[] UserName = { dicUserName.TryGetValue("Spring Yang"), dicUserName.TryGetValue("Lemon Car"),
06                                    dicUserName.TryGetValue("Associated Coffee") };
09        private void LoadCustomers()
11            AddCustomer("Spring Yang");
12            AddCustomer("Lemon Car");
13            AddCustomer("Associated Coffee");
16        private void AddCustomer(string name)
18            dicUserName.Add(name, new Customer(name));

改为

1 public void GetCustomers()
3     string[] UserName = { new Customer("Spring Yang"), new Customer("Lemon Car"), new Customer("Associated Coffee") };

七、Replace Array with Object(以对象取代数组)

动机(Motivation)

以对象替换数组。对于数组中的每个元素,以一个值域表示。

示例

3     string[] UserInfo = new string[3];
5     UserInfo[1] = "spring yang";
6     UserInfo[2] = "IT";

改为

3     User user = new User();
5     user.Name = "spring yang";
6     user.Depart = "IT";