C#BestPractices-DefineProperClasses

王朝学院·作者佚名  2016-08-28
窄屏简体版  字體: 小  |  中  |  大  |  超大  

applicationArchitecture[flash=500,400]http://s1.knowsky.com/20160211/1ifrtdwuerj03.jpg[/flash]

Define the components apPRopriately for the application and create project for each one.

[flash=500,400]http://s1.knowsky.com/20160211/hlzu1drcrer03.jpg[/flash]

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 orOperations.

类是一种模板或模具,指定了具体数据或者是行为操作等。

Unit Testing3 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

FAQ1.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、接口不能包含字段、构造函数、析构函数、静态成员或常量。

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航