gpt4 book ai didi

java - 解读 Java 中面向对象的编程概念

转载 作者:行者123 更新时间:2023-12-01 14:52:17 25 4
gpt4 key购买 nike

我一直在阅读有关面向对象的概念,但我真的迷失了。从概念上讲,我所理解的只是方法“做”某事,而类是“蓝图”。我已经阅读了所有的类比,但到目前为止,唯一对我来说真正有意义的是:循环、if then、变量赋值、原始数据类型和基本语法。

对我来说,程序就是程序。您输入指令,计算机就会执行。我想我并没有真正看到大局。

最佳答案

从天空的角度来看,OOP 的最大部分是组织和代码重用。您希望组织执行特定操作的“对象”,并且也希望能够将其重用于其他应用程序。这个想法只是让您更轻松地维护您正在做的事情、信息的位置以及它们如何协同工作。这是非常广泛的,所以让我知道你真正不理解的是什么。

将代码捆绑到单独的软件对象中具有许多好处,包括:

Modularity: The source code for an object can be written and maintained independently of the source code for other objects. Once created, an object can be easily passed around inside the system.
Information-hiding: By interacting only with an object's methods, the details of its internal implementation remain hidden from the outside world.
Code re-use: If an object already exists (perhaps written by another software developer), you can use that object in your program. This allows specialists to implement/test/debug complex, task-specific objects, which you can then trust to run in your own code.
Pluggability and debugging ease: If a particular object turns out to be problematic, you can simply remove it from your application and plug in a different object as its replacement. This is analogous to fixing mechanical problems in the real world. If a bolt breaks, you replace it, not the entire machine.

关于java - 解读 Java 中面向对象的编程概念,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14713651/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com