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

标签 java

我一直在阅读有关面向对象的概念,但我真的迷失了。 从概念上讲,我所理解的只是方法“做”某事,而类是“蓝图”。我已经阅读了所有的类比,但到目前为止,唯一对我来说真正有意义的是: 循环、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/

相关文章:

java - Java中如何从代理实例获取实现类实例

java - 尝试读取对象的 ArrayList 并将其写入二进制文件,但最终在输出中得到空值

java - 尝试在空对象引用上调用虚拟方法 'void android.view.View.setAnimation(android.view.animation.Animation)'

java - 在 Google App Engine 上读取静态 XML 文件

java - 是否可以对 JUnit 中的每个测试用例使用不同的@Before @After?

java - 用户定义的数据类型遇到错误的列类型

java - 打印字符串中数字(不是数字)的总和

java - Jsoup 谷歌搜索结果

java - Ping 函数返回所有 ping 到的 IP 地址均可访问

java - GetText() 说明 - xpath 不返回值