oops程序是什么意思_OOPS中的抽象是什么?

oops程序是什么意思

Abstraction is one of the core concepts of Object-Oriented Programming. Abstraction defines a model to create an application component. The implementation of abstraction depends on the language-specific features and processes.

抽象是面向对象编程的核心概念之一 。 抽象定义用于创建应用程序组件的模型。 抽象的实现取决于特定于语言的功能和过程。

1.什么是抽象? (1. What is Abstraction?)

Abstraction is the process of hiding the internal details of an application from the outer world. Abstraction is used to describe things in simple terms. It’s used to create a boundary between the application and the client programs.

抽象是从外部世界隐藏应用程序内部细节的过程。 抽象用于用简单的术语描述事物。 它用于在应用程序和客户端程序之间创建边界。

2.现实生活中的抽象 (2. Abstraction in Real Life)

Abstraction is present in almost all the real life machines.

几乎所有现实生活中的机器都存在抽象。

  • Your car is a great example of abstraction. You can start a car by turning the key or pressing the start button. You don’t need to know how the engine is getting started, what all components your car has. The car internal implementation and complex logic is completely hidden from the user.

    您的汽车是抽象的一个很好的例子。 您可以通过转动钥匙或按启动按钮来启动汽车。 您不需要知道发动机是如何启动的,汽车的所有部件是什么。 汽车的内部实现和复杂的逻辑对用户完全隐藏了。
  • We can heat our food in Microwave. We press some buttons to set the timer and type of food. Finally, we get a hot and delicious meal. The microwave internal details are hidden from us. We have been given access to the functionality in a very simple manner.

    我们可以用微波炉加热食物。 我们按一些按钮来设置计时器和食物类型。 最后,我们得到一顿美味的热饭。 微波内部的细节对我们来说是隐藏的。 我们已经以非常简单的方式获得了对功能的访问。

3. OOPS中的抽象 (3. Abstraction in OOPS)

Objects are the building blocks of Object-Oriented Programming. An object contains some properties and methods. We can hide them from the outer world through access modifiers. We can provide access only for required functions and properties to the other programs. This is the general procedure to implement abstraction in OOPS.

对象是面向对象编程的构建块。 一个对象包含一些属性和方法。 我们可以通过访问修饰符将它们隐藏在外部世界中。 我们只能提供对其他程序的必需功能和属性的访问。 这是在OOPS中实现抽象的一般过程。

4.抽象有哪些不同类型? (4. What are the different types of abstraction?)

There are two types of abstraction.

有两种抽象类型。

  1. Data Abstraction

    数据抽象
  2. Process Abstraction

    流程抽象

4.1)数据抽象 (4.1) Data Abstraction)

When the object data is not visible to the outer world, it creates data abstraction. If needed, access to the Objects’ data is provided through some methods.

当对象数据对外部世界不可见时,它将创建数据抽象。 如果需要,可以通过某些方法访问对象的数据。

Data Abstraction

Data Abstraction

数据抽象

4.2)流程抽象 (4.2) Process Abstraction)

We don’t need to provide details about all the functions of an object. When we hide the internal implementation of the different functions involved in a user operation, it creates process abstraction.

我们不需要提供有关对象所有功能的详细信息。 当我们隐藏用户操作中涉及的不同功能的内部实现时,它将创建流程抽象。

Process Abstraction

Process Abstraction

流程抽象

5. Java中的抽象 (5. Abstraction in Java)

Abstraction in Java is implemented through interfaces and abstract classes. They are used to create a base implementation or contract for the actual implementation classes.

Java中的抽象是通过接口抽象类实现的 。 它们用于为实际的实现类创建基本实现或合同。

Car.java: Base interface or abstract class

Car.java :基本接口或抽象类

package com.journaldev.oops.abstraction;

public interface Car {

	void turnOnCar();

	void turnOffCar();

	String getCarType();
}

ManualCar.java, AutomaticCar.java: implementation classes of Car.

ManualCar.java,AutomaticCar.java :Car的实现类。

package com.journaldev.oops.abstraction;

public class ManualCar implements Car {

	private String carType = "Manual";
	
	@Override
	public void turnOnCar() {
		System.out.println("turn on the manual car");
	}

	@Override
	public void turnOffCar() {
		System.out.println("turn off the manual car");
	}

	@Override
	public String getCarType() {
		return this.carType;
	}
}
package com.journaldev.oops.abstraction;

public class AutomaticCar implements Car {

	private String carType = "Automatic";

	@Override
	public void turnOnCar() {
		System.out.println("turn on the automatic car");
	}

	@Override
	public void turnOffCar() {
		System.out.println("turn off the automatic car");
	}

	@Override
	public String getCarType() {
		return this.carType;
	}
}

User Program: Let’s look at a test program where the Car functions will be used.

用户程序 :让我们看一下将要使用Car功能的测试程序。

package com.journaldev.oops.abstraction;

public class CarTest {

	public static void main(String[] args) {
		Car car1 = new ManualCar();
		Car car2 = new AutomaticCar();

		car1.turnOnCar();
		car1.turnOffCar();
		System.out.println(car1.getCarType());

		car2.turnOnCar();
		car2.turnOffCar();
		System.out.println(car2.getCarType());

	}

}

The client program only knows about the Car and the functions that the Car provides. The internal implementation details are hidden from the client program.

客户端程序仅了解Car以及Car提供的功能。 内部实现细节从客户端程序中隐藏。

References: Wikipedia, Oracle Docs

参考: WikipediaOracle Docs

翻译自: https://www.journaldev.com/33191/what-is-abstraction-in-oops

oops程序是什么意思

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值