How to resolve the algorithm Object serialization step by step in the E programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Object serialization step by step in the E programming language
Table of Contents
Problem Statement
Create a set of data types based upon inheritance. Each data type or class should have a print command that displays the contents of an instance of that class to standard output. Create instances of each class in your inheritance hierarchy and display them to standard output. Write each of the objects to a file named objects.dat in binary form using serialization or marshalling. Read the file objects.dat and print the contents of each serialized object.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Object serialization step by step in the E programming language
Source code in the e programming language
def makeEvent(time :int) {
return def event {
to __printOn(out) { out.print(`@@$time`) }
to __optUncall() { return [makeEvent, "run", [time]] }
to getTime() { return time }
}
}
def makeArrival(time :int, what :any, position :int) {
return def arrival extends makeEvent(time) {
to __printOn(out) {
out.print(`$what to $position $super`)
}
to __optUncall() {
return [makeArrival, "run", [time, what, position]]
}
to getWhat() { return what }
to getPosition() { return position }
}
}
def surgeon := ().diverge()
surgeon.addExit(makeEvent, "makeEvent")
surgeon.addExit(makeArrival, "makeArrival")
def objs := [makeEvent(timer.now()),
makeArrival(timer.now(), "Smith", 7)]
stdout.println(objs)
.setBytes(surgeon.serialize(objs))
stdout.println(surgeon.unserialize(.getBytes()))
You may also check:How to resolve the algorithm Closest-pair problem step by step in the zkl programming language
You may also check:How to resolve the algorithm Return multiple values step by step in the Euler programming language
You may also check:How to resolve the algorithm Ethiopian multiplication step by step in the RPL programming language
You may also check:How to resolve the algorithm Sum digits of an integer step by step in the Dart programming language
You may also check:How to resolve the algorithm Evaluate binomial coefficients step by step in the OCaml programming language