我开始与面向对象编程(OOP)和想知道:什么是序列化的意义在面向对象的说法?


当前回答

序列化是将对象转换为字节流以存储对象或将其传输到内存、数据库或文件的过程。它的主要目的是保存对象的状态,以便在需要时能够重新创建它。

其他回答

只要考虑一下下面的想法就能理解它。

序列化:

"hello world".split() returns ['hello', 'world']

反序列化:

" ".join(['hello', 'world']) returns "hello world"

序列化是指当对象的状态可以保存在文件中时,对象(内存块)转换为一种形式(例如)。

就像做饼干一样,对象是一个面团,饼干是一个序列化的面团。

所以通过“序列化”,你可以把cookie发送给你的朋友。

就像这样:-)

序列化是将内存中的对象转换为字节流的过程,这样您就可以将其存储在磁盘上或通过网络发送。

反序列化是相反的过程:将字节流转换为内存中的对象。

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.

序列化必须将二进制对象转换为XML(或其他字符串)表示形式,以便将其存储在数据库/文件中或通过web服务调用通过网络发送。反序列化是相反的过程——将XML/字符串转换回对象。