OOP中的主要概念 [英] Main concepts in OOP

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

问题描述

我曾经在一次采访中被问到"OOP的三个主要概念是什么?". 我的回答是,我认为有以下4种:

I was once asked in an interview 'What are the 3 main concepts of OOP?'. I answered by saying that in my opinion there were 4 which are as follows:

  • 继承
  • 封装
  • 抽象
  • 多态

我正确吗?

推荐答案

对于面向对象的语言,存在3个要求:

There are 3 requirements for a language to be object-oriented:

  • 仅支持封装(对象)的语言不是面向对象的,而是模块化的
  • 仅支持封装(对象)和消息传递(多态)的语言不是面向对象的,而是基于对象
  • 一种支持封装(对象),消息传递(多态性)和继承(抽象)的语言, 是面向对象的
  • a language that supports only encapsulation (objects) is not object-oriented, but it is modular
  • a language that supports just encapsulation (objects) and message-passing (polymorphism) is not object-oriented, but it is object-based
  • a language that supports encapsulation (objects), message-passing (polymorphism), and inheritance (abstraction), is object-oriented

注意:抽象是一个更笼统的概念.封装等都是抽象的类",就像子例程是一种抽象一样.请参见抽象

NOTE: Abstraction is a much more general concept; encapsulation et al are kinds of abstraction, just as a subroutine is a kind of abstraction. See Abstraction

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

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