Inheritance and polymorphism

 

sealed keyword.

base keyword.

protected keyword.

Contain/delegate model(has-a relationship):

Class A

{

}

Partial class B

{

  protected A a=new A();

}

public partial class B

{

  protected A a=new A();

  public A AProperty

  {

    set{ return a; }

    get{ a=value; }

  }

}

 

Nested type definition:

public class OuterClass

{

  public class PublicInnerClass(){}

  private class PrivateInnerClass(){}

}

 

virtual and override keyword

 

Class B: A

{

  public override sealed void GetPropertyX()

  {

    ...

   }

}

 

Abstract class(cannot new)

Abstract method only can define in abstract class.

 

Member shadowing:

Class A

{

  public string shapeName;

  public void Draw()

  {

      //doing something that we cannot modify

  }

}

 

Class B: A

{

  protected new string shapeName;

  public new void Draw()

  {

      //doing what we want

   }

}

 

Base/derive converting rule:

Object o=new A();// "is-a" relationship

Baseclass bc=new Derivedclass();

 

"as" and "is" keyword

 

"as": Convert when running,

object is not compatible will return null,

Object is null will throw NullReferenceException;

"is": not compatible will return false;

时间: 2024-11-09 04:48:07

Inheritance and polymorphism的相关文章

.NET新平台编程

For the past year or so, I've been focusing my attention on the Microsoft? .NET common language runtime platform. In my opinion, most new development will target this platform because it makes application development so much easier and faster. I also

给blood的礼物《A Programmers Introduction to Visual Basic.Net》

visual OverviewForeword viiiIntroduction 11 Why Should You Move to Visual Basic.NET? 32 Your First VB.NET Application 213 Major VB.NET Changes 494 Building Classes and Assemblies with VB.NET 735 Inheritance with VB.NET 916 Database Access with VB.NET

C# Programming guidlines

guid C# Programming guidlinessource: Thinking in C# Larry O'Brien and Bruce Eckel Prentice HallUpper Saddle River, New Jersey 07458www.phptr.com begin: This appendix contains suggestions to help guide you in performing low-level program design, and i

C# Programming Guidelines

guid source: this article is from a book named<thinking in c#>,if you are interested in the book,you'd better to have a real book made by paper :) Thinking in C# Larry O'Brien and Bruce Eckel Prentice HallUpper Saddle River, New Jersey 07458www.phpt

关于DDD领域驱动设计的理论知识收集汇总

最近一直在学习领域驱动设计(DDD)的理论知识,从网上搜集了一些个人认为比较有价值的东西,贴出来和大家分享一下: 我一直觉得不要盲目相信权威,比如不能一谈起领域驱动设计,就一定认为国外的那个Eric Evans写的那本书中的一些概念就一定是正确的,认为领域驱动设计就一定是聚合,聚合根,实体,值对象等概念.我们要有自己的思想,要有自己判断真正的领域模型该是什么样子的勇气和追求. "领域驱动设计" = "问题域模型驱动领域建模" + "领域建模驱动软件实现&q

黑马程序员 三、面向对象(1))

Java帮帮-IT资源分享网  三.黑马程序员-面向对象(1) 第三篇:  1.什么叫面向对象? 面向对象(Object-Oriented,简称 OO)就是一种常见的程序结构设计方法. 面向对象思想的基础是将相关的数据和方法放在一起,组合成一种新的复合数据类型,然后 使用新创建的复合数据类型作为项目的基础. 面向对象是一个很抽象的概念,它相对面向过程而言. 过程与对象都是一种解决问题的思想. 面向过程:强调的是功能行为,一种过程,先干啥,再干啥; 面向对象:将功能封装到对象里,强调的是具备某功能

Java基础之004-面向对象

Java基础之004-面向对象                                        35岁学习Java 1.1 面向对象概念 1.1.1理解面向对象 1)     面向对象是相对面向过程而言 2)     面向对象和面向过程都是一种思想 3)     面向过程 强调的是功能行为 4)     面向对象 将功能封装进对象,强调具备了功能的对象. 5)     面向对象是基于面向过程的. 1.1.2面向对象的特点 1)     是一种符合人们思考习惯的思想 2)     可

Java基础-06.总结二维数组,面向对象

1:二维数组(理解) (1)元素是一维数组的数组.(2)格式:A:数据类型[][] 数组名 = new 数据类型[m][n];B:数据类型[][] 数组名 = new 数据类型[m][];C:数据类型[][] 数组名 = new 数据类型[][]{{...},{...},{...}};D:数据类型[][] 数组名 = {{...},{...},{...}}; /*二维数组:就是元素为一维数组的一个数组. 格式1:数据类型[][] 数组名 = new 数据类型[m][n]; m:表示这个二维数组有

【OH】Glossary Oracle词汇表(上)

Glossary [OH]Glossary Oracle词汇表(上) Oracle? Multimedia DICOM Developer's Guide 11g Release 2 (11.2) E10778-03 Glossary ● anonymity document An XML document that specifies the set of attributes to be made anonymous, and defines the actions required to