C# Best Practices - Define Proper Classes
Application Architecture
Define the components appropriately for the application and create project for each one.
What is Class?
3 Things: Visual Things, Business Things (Domain Entities), Application Things (like Logging & Email Generation)
3 Types: User interface classes, Domain entity classes, Library class
Class is a template or mold,specifies the traits or data,specifies the behavior or operations.
类是一种模板或模具,指定了具体数据或者是行为操作等。
Unit Testing
3 Advantages:
Higher Code Quality, Faster and Easier Debugging, Repeatable
Features:
Tests the behavior of a unit of code (often a method), Automated, Defined with code,Identifies errors
Tools:
MSTest, NUnit
Steps:
1.Define the test scenarios, 2.Generate the tests, 3.Execute the tests
Arrange -> Act -> Assert
FAQ
1.Why is a layer architecture important?
Logical components are easier to create,change,extend and maintain
Code are easier to reuse
2.What is a class?
A template for the objects created at runtime
Specifies the data and operations for each entity
3.What are the benefits of unit testing?
Higher quality code,faster and easier debugging,and they are repeatable over the life of the application
类定义中的访问修饰符
无或internal:只能在当前项目中访问类
public:可以在任何地方访问类
abstract或internal abstract:不能实例化,只能供继承之用(只能在当前项目中访问)
public abstract:同上,但可以在任何地方访问
sealed或internel sealed:不能供派生之用,只能实例化(只能在当前项目中访问)
public sealed:同上,但可以在任何地方访问
接口和抽象类
类似:
都不能实例化,都包含可以由派生类继承的成员。
区别:
1、派生类只能继承一个基类,但类可以继承任意多个接口。
2、抽象类的成员可以拥有代码体(即代码实现),而接口成员没有代码体,都必须在使用接口的类上实现。
3、接口成员是公共的,而抽象类的成员可以是private, protected, internal or protected internal。
4、接口不能包含字段、构造函数、析构函数、静态成员或常量。
C# Best Practices - Define Proper Classes的更多相关文章
- C# Best Practices - Building Good Classes
Building a Class The last four refer as members Signature Accessiblity modifier (Default:internal) c ...
- C# Best Practices - Define Fields Appropriately
Backing Fields private string description; private int productId; Features A variable in a class Hol ...
- MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.3 Displaying Classes in a Layer
MapServer Tutorial——MapServer7.2.1教程学习——第一节用例实践:Example1.3 Displaying Classes in a Layer 一.前言 关于第一节的 ...
- [转]50 Tips for Working with Unity (Best Practices)
About these tips These tips are not all applicable to every project. They are based on my experience ...
- Unity 最佳实践
转帖:http://www.glenstevens.ca/unity3d-best-practices/ 另外可以参考:http://devmag.org.za/2012/07/12/50-tips- ...
- ExtJS笔记2 Class System
For the first time in its history, Ext JS went through a huge refactoring from the ground up with th ...
- 6.Type and Member Basics
1.The Different Kinds of Type Members 1.Constants:a symbol that identifies a never-changing data val ...
- Automake
Automake是用来根据Makefile.am生成Makefile.in的工具 标准Makefile目标 'make all' Build programs, libraries, document ...
- Class loading in JBoss AS 7--官方文档
Class loading in AS7 is considerably different to previous versions of JBoss AS. Class loading is ba ...
随机推荐
- MyBatis 最常见错误,启动时控制台无限输出日志
你是否遇到过下面的情况,控制台无限的输出下面的日志: Logging initialized using ‘class org.apache.ibatis.logging.log4j.Log4jImp ...
- POJ 2686 Traveling by Stagecoach 壮压DP
大意是有一个人从某个城市要到另一个城市(点数<=30) 然后有n个马车票,相邻的两个城市走的话要消耗掉一个马车票. 花费的时间呢,是马车票上有个速率值,用边/速率就是花的时间. 问最后这个人花费 ...
- hdu4288 Coder
Coder Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- HDU 3037 Saving Beans(Lucas定理的直接应用)
解题思路: 直接求C(n+m , m) % p , 由于n , m ,p都非常大,所以要用Lucas定理来解决大组合数取模的问题. #include <string.h> #include ...
- Dyanmics CRM您无法登陆系统。原因可能是您的用户记录或所属的业务部门在Microoft Dynamics CRM中已被禁用
当在操作CRM时,做不论什么的写操作包含创建数据.更新数据.都会提示以下截图中的错误:"您无法登陆系统.原因可能是您的用户记录或所属的业务部门在Microoft Dynamics CRM中已 ...
- Float类型在SQL中计算
- SSIS: 把存储在数据库中的图片导出来
Data Flow Task Step 1 获取二进制图片数据 )='C:\labs\Images\' SELECT ThumbNailPhoto,@path+ThumbnailPhotoFileNa ...
- 修改UISearchBar背景颜色
UISearchBar是由两个subView组成的,一个是UISearchBarBackGround,另一个是UITextField. 要IB中没有直接操作背景的属性.方法一:是直接将 UISearc ...
- SQL server 和Oracle 序列
1,SQL Server序列创建与使用 BEGIN IF EXISTS (SELECT * FROM sysobjects WHERE name = 'event_seq') DROP SEQUENC ...
- JAVA编译中拒绝访问的问题及解决方案
在java编译时出现,可以将C盘内的文件转移到其他盘,此问题可能是权限不足不能够读取C盘文件造成的. 文件名与类名要一致,包括大小写,也是要一致!