1 00:00:06,450 --> 00:00:06,930 Hello. 2 00:00:07,470 --> 00:00:10,800 In this video, we're going to talk about Question 18. 3 00:00:11,220 --> 00:00:12,990 What is civilization? 4 00:00:13,590 --> 00:00:21,540 Civilization is the process of converting an object into a format that can be stored in memory or transmitted 5 00:00:21,540 --> 00:00:22,620 over a network. 6 00:00:22,860 --> 00:00:31,680 For example, the object can be converted into a text file containing Dyson or Azimo or a binary file. 7 00:00:32,130 --> 00:00:38,940 This realization is the opposite process using the content of a file to recreate objects. 8 00:00:39,720 --> 00:00:40,350 All right. 9 00:00:40,710 --> 00:00:45,150 Here is a simple program that simply reads some input from the user. 10 00:00:45,480 --> 00:00:48,630 It uses this input to build a person object. 11 00:00:49,080 --> 00:00:55,740 Here is what I would like us to do after this program is run for the first time and the personal data 12 00:00:55,740 --> 00:00:56,460 is read. 13 00:00:56,640 --> 00:01:03,600 I would like to store the person object in memory, for example, as a text file with example if we 14 00:01:03,600 --> 00:01:05,580 run this program for a second time. 15 00:01:05,910 --> 00:01:07,920 It shouldn't ask those questions again. 16 00:01:08,310 --> 00:01:13,440 It should read this data from the XML file and build the person object. 17 00:01:14,220 --> 00:01:16,020 All right, so let's do it. 18 00:01:16,560 --> 00:01:23,010 We'll start by writing a method that serialize is a person and convert it into a string, which will 19 00:01:23,010 --> 00:01:25,490 later be the content of the XML file. 20 00:01:30,860 --> 00:01:37,370 There is no point in reinventing the wheel, so we'll use the built in Xmas sterilizer class. 21 00:02:08,720 --> 00:02:10,010 Let's see what happened here. 22 00:02:10,490 --> 00:02:17,990 The Maximo serializing across serialize is the object it takes as a parameter and writes the results 23 00:02:17,990 --> 00:02:19,970 thrilling to the Examiner writer. 24 00:02:20,510 --> 00:02:27,410 I created this writer with settings saying that the result would be indented, so it looks more readable 25 00:02:27,410 --> 00:02:28,430 in the text file. 26 00:02:28,820 --> 00:02:29,900 Let's see if it works. 27 00:02:40,940 --> 00:02:48,290 And here is the exam result seems like our civilization is working, what we need to do now is save 28 00:02:48,290 --> 00:02:49,850 it to an ExxonMobile. 29 00:03:02,250 --> 00:03:03,510 Let's make sure it works. 30 00:03:09,610 --> 00:03:13,360 I'm going to check if the file has been saved to the output folder. 31 00:03:17,760 --> 00:03:24,060 And here it is, seems like the saving of the civilized object works. 32 00:03:26,070 --> 00:03:32,160 Alright, so what we want to do now is when the application starts, we should check if such a file 33 00:03:32,160 --> 00:03:32,910 exists. 34 00:03:33,240 --> 00:03:39,480 If so, instead of building the person object based on the user's answers, we should just build it 35 00:03:39,480 --> 00:03:41,550 from the data stored in the file. 36 00:03:55,160 --> 00:04:00,830 We'll start by reading the existing file and then will decrease its content. 37 00:04:44,930 --> 00:04:45,620 All right. 38 00:04:46,070 --> 00:04:47,420 Similarly, as before. 39 00:04:47,720 --> 00:04:50,960 I'm just using the existing classes first. 40 00:04:51,110 --> 00:04:57,530 I'm reading the file with the screen reader and I'm building a special example text reader from it. 41 00:04:57,800 --> 00:05:04,130 Finally, I'm using the example centralized to decentralized, the text that has been read and built 42 00:05:04,130 --> 00:05:05,630 a person object from it. 43 00:05:06,110 --> 00:05:07,490 Let's make sure it works. 44 00:05:10,010 --> 00:05:10,670 All right. 45 00:05:10,820 --> 00:05:18,080 Looking good in this simple program, we used the example serialization, but there are different formats. 46 00:05:18,560 --> 00:05:21,260 One of the most common formats is Jason. 47 00:05:21,530 --> 00:05:27,860 The name comes from JavaScript object notation because it derives from JavaScript objects format. 48 00:05:28,130 --> 00:05:35,450 Jason is typically used for communication over a network, for example, when you fill a form on a website. 49 00:05:35,540 --> 00:05:42,180 Most likely, the data from the form is wrapped in JSON format and sent to the server, which then reads 50 00:05:42,200 --> 00:05:45,140 it and translate it to see sharp objects. 51 00:05:45,590 --> 00:05:51,800 Of course, assuming the backend is written C-sharp, this is how the data we thought as an example 52 00:05:51,920 --> 00:05:53,810 would look like in JSON format. 53 00:05:54,870 --> 00:06:02,160 If you want to your and decentralize objects using day soon, I recommend using Jason does not library. 54 00:06:02,340 --> 00:06:09,810 Developed by Newton Soft in the resources attached to this lecture, I'm showing serialization and disassociation 55 00:06:09,900 --> 00:06:11,220 using this library. 56 00:06:11,760 --> 00:06:14,580 One more thing that we should mention on this topic. 57 00:06:14,850 --> 00:06:19,560 The interviewer can ask you What does the serial zebu attribute to do? 58 00:06:19,970 --> 00:06:21,990 First, let me show you how it looks. 59 00:06:24,180 --> 00:06:30,660 Some people think this attribute must be added to a type if we want to serialized it to example or JASON 60 00:06:30,660 --> 00:06:31,260 format. 61 00:06:31,560 --> 00:06:33,600 But actually, this is not correct. 62 00:06:34,050 --> 00:06:41,400 This attribute indicates that instances of a type can be serialized with binary formatter or soap formatter. 63 00:06:41,940 --> 00:06:45,510 It is not required, for example, adjacent serialization. 64 00:06:45,840 --> 00:06:52,650 The binary, for matter, symbolizes this object to a binary format, so simply speaking, a chain of 65 00:06:52,650 --> 00:06:53,940 zeros and ones. 66 00:06:54,480 --> 00:06:59,580 The soap formatter uses the soap format, which is a little similar to the example. 67 00:07:00,180 --> 00:07:07,260 Let's summarize Serialization is a process of translating objects into a format that can be stored as 68 00:07:07,260 --> 00:07:10,410 a file and possibly transmitted over a network. 69 00:07:10,770 --> 00:07:14,100 Serialized objects can later be reconstructed. 70 00:07:14,580 --> 00:07:21,960 The interview questions related to this topic could be what are uses of civilization to send objects 71 00:07:21,960 --> 00:07:28,380 over on network or to store objects in the fire for later reconstruction, or even to store them in 72 00:07:28,380 --> 00:07:29,250 a database? 73 00:07:29,700 --> 00:07:33,450 This is sometimes done to save a snapshot of an object. 74 00:07:33,570 --> 00:07:39,360 Every time I use it to make some changes to it so we can log the history of the objects tenders. 75 00:07:39,960 --> 00:07:42,750 What does the serialized attribute to? 76 00:07:43,440 --> 00:07:49,860 This attribute indicates that instances of a type can be serialized with binary from water or soap, 77 00:07:49,860 --> 00:07:50,520 for matter. 78 00:07:50,880 --> 00:07:54,510 It is not required, for example, or decentralization. 79 00:07:55,080 --> 00:07:57,120 What is this realization? 80 00:07:57,570 --> 00:08:00,750 This realization is the opposite of the realization. 81 00:08:01,020 --> 00:08:04,650 It's using the content of a file to recreate objects. 82 00:08:05,250 --> 00:08:06,740 All right, that's it. 83 00:08:06,750 --> 00:08:07,950 About serialization. 84 00:08:08,310 --> 00:08:11,160 Thanks for watching and see you in the next lecture.