我开始与面向对象编程(OOP)和想知道:什么是序列化的意义在面向对象的说法?
当前回答
序列化是将对象转换为字节流以存储对象或将其传输到内存、数据库或文件的过程。它的主要目的是保存对象的状态,以便在需要时能够重新创建它。
其他回答
When instantiating (constructing) the actual object(the thing) from a class (blueprint) there is a need to save the object (thing) by serializing it (breaking it down to its basic atomic structure) to a space in memory. (Kind of like Star Treks Transporter). You break the thing down into it stream of information that can be transported somewhere and stored. Then when you want to reconstruct the thing you just pull the atomically stored instance back into the object. Different from instaniation.
序列化是将对象转换为可存储的位序列。
所以你可以保存这个序列到一个文件,db或通过网络发送。
稍后,您可以将其反序列化为实际对象,并在需要时重用它。
Web服务和AJAX是序列化最常见的例子。对象在向客户端发送响应之前被序列化。
简单地说,序列化是一个将对象转换为字节流的过程,这样它就可以通过网络传输或存储在持久存储器中。
反序列化则完全相反——从网络或持久化存储中获取字节流,并将其转换回具有相同状态的Object。
需要理解的是如何解释或操作这些字节流,以便我们得到完全相同的对象/相同的状态。有很多方法可以实现这一点。其中一些是-
XML: Convert Object to XML, transfer it over a network or store it in a file/db. Retrieve it and convert it back to the object with same state. In Java we use JAXB(Java architecture for XML binding) library.(From java 6 it comes bundled with JDK). JSON: Same can be done by converting the Object to JSON (JavaScript Object notation). Again there is GSON library that can be used for this. Or we can use the Serialization that is provided by the OOP language itself. For example, in Java you can serialize an Object my making it implement Serializable interface and writing to Object Stream.
序列化是将数据转换为由字节组成的线性“字符串”。
其他人或多或少也说过同样的事情,但我强调计算机模型要求数据适合一维寻址RAM或持久存储。
大多数“数据”本质上是可序列化的(即使你必须将抽象模型简化为线性模型);不可序列化的是网络连接或复杂的基于状态的机器,如解析器。
序列化是将对象转换为字节流以存储对象或将其传输到内存、数据库或文件的过程。它的主要目的是保存对象的状态,以便在需要时能够重新创建它。
推荐文章
- 为什么不使用异常作为常规的控制流呢?
- 什么是序列化?
- 我如何复制一个哈希在Ruby?
- 每个递归都可以转换成迭代吗?
- 为什么生成较长的serialVersionUID而不是简单的1L?
- 将流转换为字符串并返回
- 什么是ORM,它是如何工作的,我应该如何使用它?
- 我能在服务器端应用程序(PHP、Ruby、Python等)上读取URL的哈希部分吗?
- 多少个参数是太多?
- Parcelable遇到IOException写入序列化对象getactivity()
- 对于不可变集合上的非突变“add”方法,最好的名称是什么?
- foo到底是什么意思?
- 不带空格的Python - json
- 打印对象的所有属性
- foreach和map有区别吗?