Home Database Mysql Tutorial 面向对象的特征

面向对象的特征

Jun 07, 2016 pm 04:11 PM
uml learn object feature For

在UML中,了解到了面向对象,所以对面向对象有个初步的认识,为以后能够更加方便的理解面向对象打下一个好的基

在UML中,了解到了面向对象,所以对面向对象有个初步的认识,为以后能够更加方便的理解面向对象打下一个好的基础。

抽象、封装、继承和多态,这是面向对象技术的四大基本特征,也是面向对象程序设计思想的组成。正是这些特征,使得程序的安全性、可靠性和可重用性得到保证,并且经过发展,面向对象的思想应用范围更加广泛,不光是软件,在硬件、人工智能、分布式计算、操作系统等领域的应用也越来越重要。

抽象

抽象可以忽略事物中与当前目标无关的非本质特征、强调与当前目标有关的特征。比如地球仪,我们的目标是通过地球仪来认识地球的全貌,而不考虑地球仪上的部分与地球对应部分的比例是多少。这只是一个地球的模型,抽象的模型越简单、展露的特点越少,模型就越通用。我们通过观察地球仪,可以找到大家公认的七大洲四大洋,并不一定要知道每个大洲或大洋的具体模样,在地球仪上都有,随便一看就可以分辨出来。

抽象也可以对信息进行分类处理,将对象按照一定的标准进行划分,实现抽象模型的层次结构,更加通用和易处理。这样,抽象出来的类就为对象的重用提供了保障。

封装

把对象的状态和行为绑到一起的机制,使对象形成一个独立的整体,并且尽可能的隐藏对象的内部细节。封装的信息屏蔽作用反应了事物的相对独立性,帮助保护数据的完整性。绑定有两个含义:一时把对象的全部状态和行为结合在一起,形成一个不可分割的整体。对象的私有属性只能够由对象的行为来修改和读取;二是尽可能隐蔽对象的内部细节,与外界的联系只能通过外部接口来实现。封装的结果是使对象以外的部分不能随意更改对象的内部属性或状态,可以通过公共访问控制器来控制对象封装了的属性或状态的改变。

在面向对象的程序设计中,不能一味的限制对象的属性被外部直接读取,否则将增加很多无用的操作,要对对象的属性进行分析后再设置。

继承

各种事物之间不光有它们的共性,还有各个事物自己的特性,如果忽略了事物的特性,那么世界就会变得一层不变,失去了特色的精彩世界。事物的各自的特色和个性是这个层次的世界稳固的原因,这些特色也是来区别事物共性的部分,相辅相成。

与抽象对比,抽象是把事物间的特性舍弃,抽象出事物间的共性成为一个类;而继承则是提取了事物间的不同特性形成的多个类,这个类具有前一个类的全部特征,是前一个类的子集,形成了一个层次的结构。这样就可以看出,继承和抽象是两个相逆的过程,抽象是从多个对象中抽象出来了共性的类,是一个由多到少的过程;继承则是从对象类中分层为多个具有自己特性的子类,是一个由少到多的过程。


特别的,继承意味着“自动拥有”,即在特殊类中不必重新对已经存在一般类中的所定义过的属性和行为进行定义,而是特殊类自动的,隐含的拥有其一般类的属性和行为,且继承后这些属性和行为都是自己确实存在的。一般类称为基类,特殊类称为派生类。以上图为例,小学生和中学生,大学生,研究生这四个特殊类是学生类这个一般类的子类,也是从学生类中继承来的新类,它们自动的拥有了所有属于学生类的属性和方法,而同时它们又有自己的特性,不用再重新定义在学生类中已经定义过的属性和方法。学生类是基类,小学生等类是派生类。

继承在面向对象软件的开发过程中有如下目的,或者可以说是优势:1.对类的描述更加简洁;2.能够重用和扩展现有类库资源;3.是软件易于维护和修改。

多态

多态是指两个或多个属于不同类的对象,对于同一个消息或方法调用所作出的不同相应的能力。在面向对象的程序设计中,多态性是指在两个或多个属于不同类的同一函数名对应于多个具有相似功能的不同函数,可以使用相同的调用方式来调用这些具有不同功能的同名函数。这个可以这样理解,在一个图形的基类中有一个方法是画图,派生类矩形和派生类椭圆中也有画图的方法,但是通过同一个画图动作,矩形类画出来的图形是矩形,椭圆中画图画出来的是椭圆。

继承性和多态性的结合,实现了软件的个性化设计。面向对象中的抽象和继承更加重要,对面向对象的理解非常有帮助,当对面向对象陌生的时候可以以这两个为突破点,全面理解面向对象。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Convert an array or object to a JSON string using PHP's json_encode() function Convert an array or object to a JSON string using PHP's json_encode() function Nov 03, 2023 pm 03:30 PM

JSON (JavaScriptObjectNotation) is a lightweight data exchange format that has become a common format for data exchange between web applications. PHP's json_encode() function can convert an array or object into a JSON string. This article will introduce how to use PHP's json_encode() function, including syntax, parameters, return values, and specific examples. Syntax The syntax of the json_encode() function is as follows: st

Learn about Redisson caching technology Learn about Redisson caching technology Jun 21, 2023 am 09:54 AM

Redisson is a Redis-based caching solution for Java applications. It provides many useful features that make using Redis as a cache in Java applications more convenient and efficient. The caching functions provided by Redisson include: 1. Distributed mapping (Map): Redisson provides some APIs for creating distributed maps. These maps can contain key-value pairs, hash entries, or objects, and they can support sharing among multiple nodes.

At a glance: A quick overview of how to open JSP files At a glance: A quick overview of how to open JSP files Jan 31, 2024 pm 09:28 PM

JSP file opening method JSP (JavaServerPages) is a dynamic web page technology that allows programmers to embed Java code in HTML pages. JSP files are text files that contain HTML code, XML tags, and Java code. When a JSP file is requested, it is compiled into a JavaServlet and then executed by the web server. Methods of Opening JSP Files There are several ways to open JSP files. The easiest way is to use a text editor,

How to convert MySQL query result array to object? How to convert MySQL query result array to object? Apr 29, 2024 pm 01:09 PM

Here's how to convert a MySQL query result array into an object: Create an empty object array. Loop through the resulting array and create a new object for each row. Use a foreach loop to assign the key-value pairs of each row to the corresponding properties of the new object. Adds a new object to the object array. Close the database connection.

Use Python's __contains__() function to define the containment operation of an object Use Python's __contains__() function to define the containment operation of an object Aug 22, 2023 pm 04:23 PM

Use Python's __contains__() function to define the containment operation of an object. Python is a concise and powerful programming language that provides many powerful features to handle various types of data. One of them is to implement the containment operation of objects by defining the __contains__() function. This article will introduce how to use the __contains__() function to define the containment operation of an object, and give some sample code. The __contains__() function is Pytho

What is the difference between arrays and objects in PHP? What is the difference between arrays and objects in PHP? Apr 29, 2024 pm 02:39 PM

In PHP, an array is an ordered sequence, and elements are accessed by index; an object is an entity with properties and methods, created through the new keyword. Array access is via index, object access is via properties/methods. Array values ​​are passed and object references are passed.

Use Python's __le__() function to define a less than or equal comparison of two objects Use Python's __le__() function to define a less than or equal comparison of two objects Aug 21, 2023 pm 09:29 PM

Title: Using Python's __le__() function to define a less than or equal comparison of two objects In Python, we can define comparison operations between objects by using special methods. One of them is the __le__() function, which is used to define less than or equal comparisons. The __le__() function is a magic method in Python and is a special function used to implement the "less than or equal" operation. When we compare two objects using the less than or equal operator (<=), Python

What is the Request object in PHP? What is the Request object in PHP? Feb 27, 2024 pm 09:06 PM

The Request object in PHP is an object used to handle HTTP requests sent by the client to the server. Through the Request object, we can obtain the client's request information, such as request method, request header information, request parameters, etc., so as to process and respond to the request. In PHP, you can use global variables such as $_REQUEST, $_GET, $_POST, etc. to obtain requested information, but these variables are not objects, but arrays. In order to process request information more flexibly and conveniently, you can

See all articles