English 中文(简体)
何时,我应去做一个交错课,何时做一个抽象的课? [复制]
原标题:When should I go for an Interface and when for an abstract class? [duplicate]
  • 时间:2010-06-21 09:50:31
  •  标签:
  • .net
  • oop
This question already has answers here:
Closed 12 years ago.

Possible Duplicate:
Interface vs Base class

I was just thinking about when should some one go for Interface rather than an abstract class. I know interface is useful for multiple inheritance but apart from that what other advantages it provides over abstract class?

问题回答

相互关系界定了行为合同。 如果你想要提供共同执行或共同守则等,则使用抽象课程。

接口用于表示某种类型的provides执行,以便预期接口的代码知道如何处理。 只要您的习俗阶层实施交接,我的公众人物就能够把你的班子作为我的接口并与之合作。

摘要为衍生类型提供执行,接口要求执行类型。

浏览器比抽象的班级更喜欢接口。 如果你需要提供某种执行,就设立一个抽象的类别,以落实你的基调。 因此,你可以提供一些执行,而你则选择延长你的抽象类别或实施接口。

摘要班级迫使你延长合同期。 既然你们的构成比继承更可取,那么就更容易使你自己的阶级与你的个人经历相处,而后者则实施交错和与你的包裹相提并进。 (例如,战略模式)

了解有效的java,项目18,以获得进一步信息。

一类人可以实施多个接口,但只能继承一个抽象的类别。

此外,还有异质。 授予一个班级表示<代码>is-a 关系,在实施接口时,您有<代码>has-a 关系。

利用接口和构成(所谓的strategy) 模式)使设计非常灵活,可在操作时加以改变。





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签