解释OOP原则的最佳方法? [英] Best way to explain OOP Principles?

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

问题描述

   1. Abstraction
   2. Encapsulation
   3. Inheritance 
   4. Polymorphism 

例如在面试中如何最好地解释这些概念?

How to best explain these concepts, for example, in an interview?

推荐答案

1.抽象

仅向用户显示他需要的必要内容,而不显示其他内容 信息(使用公共私人信息,受保护).当完成时进行抽象 我们需要从某些类继承,但不要实例化 该类的对象.

Show only necessary thing to user that he required, not extra information (use public private, protected). Abstraction is done when we need to inherit from certain class but do not instantiate the objects of that class.

2.封装

将所有相关内容归为一类. IE.封装是 在单个单元中包装/绑定数据和成员函数.在 简单,抽象隐藏了实现,封装是 隐藏数据.

Group all relevant things together. I.e. encapsulation is wrapping/binding up of data and member functions in single unit. In simple, abstraction is hiding the implementation and encapsulation is to hide data.

3.继承

如果已经存在某些东西,为什么我应该重新创建它(与重新发明轮子一样).使用继承继承该类的所有内容 进入你的班级.继承使您可以创建新类,以重用,扩展和修改其他类中定义的行为

If something already exist, why should I recreate it (same as re-inventing a wheel). Use inheritance to inherit all things of that class into your class. Inheritance enables you to create new classes that re-use, extend and modify the behaviour that is defined in other classes

4.多态性

当对象在不同情况下表现出不同的行为时. 以简单的方式,可以以不同的方式/形式处理消息.

When an object exhibits different behavior in different situation. In simple way, when a message can be processed in different ways/forms.

这篇关于解释OOP原则的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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