有关OOP的一些问题 [英] Some Questions about OOP

查看:128
本文介绍了有关OOP的一些问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以回答这些问题吗?

1.我们如何决定何时使用抽象或接口(即,在哪种情况下我们决定使用两者之一)

2.使用抽象的好处是什么?

请提供一些现实生活中的例子

Can any one reply these questions?

1. How can we decide when to use Abstraction or interfaces( ie In which scenario we decide to use either of one)

2. What is the advantage of using Abstraction?

Kindly provide some real life examples

推荐答案

首先让我澄清一件事,它们是术语抽象" "之间的区别.抽象类" .

我想您想知道接口" 抽象类" 之间的区别.

下面的文章可以帮助您理解抽象" 抽象类" 接口" .
面向对象编程概念(OOP)简介及更多

已更新-
这是关于面向对象编程概念的另一篇好文章.
我如何向妻子解释OOD
First let me clear one thing, their is difference between terms "Abstraction" and "Abstract Class".

I guess you want to know difference between "Interface" and "Abstract Class".

Below Article may help you in understanding "Abstraction", "Abstract Class" and "Interface".
Introduction to Object Oriented Programming Concepts (OOP) and More

Updated -
Here is one more good Article on Object Oriented Programming concepts.
How I explained OOD to my wife


如果您阅读了接下来,您可以有一个更好的主意.

抽象类与接口 [
If you read the following, you can have a better idea.

Abstract Class versus Interface[^]


这里是一个简短的答案

1)当子类将共享行为时,选择一个抽象类,因此这些共享行为的具体实现将放在抽象类中.如果子类型不共享行为,请使用接口.

2)您可以在抽象类中实现行为/功能,而抽象类不能使用接口.但是,如果子类共享这些行为/功能,那么这只是一个优势.

我建议您阅读这本书
Here''s a short answer

1) Go for an abstract class when the sub classes will share behavior, so the concrete implementation of these shared behaviors would be placed in the abstract class. if the sub types won''t share behavior go for an interface.

2) You can implement behaviors/features in an abstract class which you can''t with an interface. However it''s only an advantage if the sub classes share these behaviors/features.

I suggest you read this book Object-Oriented Software Construction[^] if want very good insight into software design.


这篇关于有关OOP的一些问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆