《你必须知道的.NET》读书笔记

一、OO大智慧

对象的构造过程:首先会在内存中分配一定的存储空间,然后初始化其附加成员,最后,再调用构造函数执行初始化

表1-1 访问修饰符

访问修饰符 访问权限
public   对访问成员没有先知,属于最高级别访问权限
protected 可以访问包含类和该类派生的类
internal 可以访问程序集内的类
protected internal  protected or internal ,访问同一个程序集的对象,或者该类及其子类都可以访问
private   访问仅限于该类型

 

 

 

 

 

 

 

关注对象原则和执行就近原则

View Code
 1     public abstract class Animal
 2     {
 3         public abstract void ShowType();
 4         public void Eat()
 5         {
 6             Console.Write("Animals is always Eating");
 7         }
 8     }
 9     public class Bird : Animal
10     {
11         public string type = "Bird";
12         public override void ShowType()
13         {
14             Console.Write("Type is {0}", type);
15         }
16         private string color;
17         public string Color
18         {
19             get { return color; }
20             set { color = value; }
21         }
22     }
23     public class Chicken : Bird
24     {
25         public string type = "chicken";
26         public override void ShowType()
27         {
28             Console.Write("Type is {0}", type);
29 
30         }
31         public void ShowColor()
32         {
33             Console.Write("Color is {0}", Color);
34         }
35     }
36     class Program
37     {
38         static void Main(string[] args)
39         {
40             Bird bird = new Chicken();
41             Console.Write(bird.type);
42             bird.ShowType();
43             Console.ReadLine();
44         }
45     }

面向对象的原则:多组合,少继承,低耦合,高内聚

多态的分类

1、基类继承式多态

2、接口实现式多态

 

 

posted @ 2013-04-25 22:48  晴丸子  阅读(188)  评论(0编辑  收藏  举报