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 ...
随机推荐
- FPC Trace Pattern Layout Design Notices (軟板線路設計注意事項)
整理了一些軟板(FPCB/Flex Cable)製造廠關於線路設計的要求 (Design Guide)以避免應用上的品質問題. 1.Relationship between Through Hole, ...
- 电商网站前端架构#1 多页面 vs 单页面
课程地址:http://www.imooc.com/learn/186 讲师:远人 课程基础: html css js ,做过一些项目. 多页面 我们往常使用的web服务大多是多页面形式,依靠后端的架 ...
- SQL练习之不破坏应用程序现有查询的修改模式
当我还是一个菜鸟的时候,当然现在也是,当我的软件需求发生变化时,并且数据库设计同样要求发生变化,我通常会放弃原有的代码(或者对原有的代码进行大改),先在我知道了两个不破坏应用程序现有查询的修改模式,下 ...
- api文档生成工具 C#
要为编写的程序编写文档,这是件费力气的事,如果能自动生成就好了. 不怕做不到,就怕想不到.这不,搜索到了Sandcastle 比较好的参考文章: 1.Sandcastle官方网址: http://sh ...
- Android入门——UI(2)
介绍SeekBar拖动条控件.ProgressBar进度条控件.DatePicker日历控件.TimePicker时间控件 <?xml version="1.0" encod ...
- 转发年浩大神的spfa算法
http://www.cnblogs.com/superxuezhazha/p/5426624.html #include<iostream> #include<stdio.h> ...
- iOS开发通过代码方式使用AutoLayout (NSLayoutConstraint + Masonry)
iOS开发通过代码方式使用AutoLayout (NSLayoutConstraint + Masonry) 随着iPhone6/6+设备的上市,如何让手头上的APP适配多种机型多种屏幕尺寸变得尤为迫 ...
- C学习之结构体
结构体(struct) 结构体是由基本数据类型构成的.并用一个标识符来命名的各种变量的组合,结构体中可以使用不同的数据类型. 1. 结构体说明和结构体变量定义 在Turbo C中, 结构体也是一种数据 ...
- Nancy 搭建
Nancy 框架 1.是一个轻量级用于构建http相应的web框架: 2.与mvc类似,有自己的路由机制: 3.可以处理 DELETE , GET , HEAD , OPTIONS , ...
- Spring管理Hibernate
为什么要用Hibernate框架? 既然用Hibernate框架访问管理持久层,那为何又提到用Spring来管理以及整合Hibernate呢? 首先我们来看一下Hibernate进行操作的步骤.比如添 ...