我开始与面向对象编程(OOP)和想知道:什么是序列化的意义在面向对象的说法?
当前回答
序列化是指当对象的状态可以保存在文件中时,对象(内存块)转换为一种形式(例如)。
就像做饼干一样,对象是一个面团,饼干是一个序列化的面团。
所以通过“序列化”,你可以把cookie发送给你的朋友。
就像这样:-)
其他回答
序列化只不过是将Java支持的对象转换为文件支持的形式
(OR)
将Java支持的形式转换为网络支持的形式..序列化的主要范围只是将数据从一层传输到另一层…只有序列化的对象,我们可以通过网络发送。
序列化是将对象转换为字节流以存储对象或将其传输到内存、数据库或文件的过程。它的主要目的是保存对象的状态,以便在需要时能够重新创建它。
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.
只要考虑一下下面的想法就能理解它。
序列化:
"hello world".split() returns ['hello', 'world']
反序列化:
" ".join(['hello', 'world']) returns "hello world"
简单地说,序列化是一个将对象转换为字节流的过程,这样它就可以通过网络传输或存储在持久存储器中。
反序列化则完全相反——从网络或持久化存储中获取字节流,并将其转换回具有相同状态的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.
推荐文章
- 为什么不使用异常作为常规的控制流呢?
- 什么是序列化?
- 我如何复制一个哈希在Ruby?
- 每个递归都可以转换成迭代吗?
- 为什么生成较长的serialVersionUID而不是简单的1L?
- 将流转换为字符串并返回
- 什么是ORM,它是如何工作的,我应该如何使用它?
- 我能在服务器端应用程序(PHP、Ruby、Python等)上读取URL的哈希部分吗?
- 多少个参数是太多?
- Parcelable遇到IOException写入序列化对象getactivity()
- 对于不可变集合上的非突变“add”方法,最好的名称是什么?
- foo到底是什么意思?
- 不带空格的Python - json
- 打印对象的所有属性
- foreach和map有区别吗?