In a language that supports OOP paradigm, we have the following code that serializes the content of a shopping cart to JSON format:
class ShoppingCart
private content : Dictionary<int, string>
public function serialize() : string
return new JsonSerializer().serialize(content.clone())
end function
end class
class JsonSerializer
public function serialize(value : Dictionary<int, string>) : string
' Code that serializes dictionary to JSON format and returns it as string
end function
end class
A client wants to have the possibility of allowing loosely coupled plugins to be able to serialize the shopping cart content to their own formats (e.g., XML). Select lines of code that, together, would extend the code above to allow this.
(Select all acceptable answers.)
class JsonSerializer
Should be changed to:
class JsonSerializer inherits ISerializer
interface ISerializer
public function serialize(Dictionary<int, string>) : string
end interface
enumeration SerializerType
Json,
Xml
end enumeration
public function serialize(serializer : SerializerType) : string
if(serializer == SerializerType.Json)
return new JsonSerializer().serialize(content.clone())
else if(serializer == SerializerType.Xml)
return new XmlSerializer().serialize(content.clone())
else
throw Error("Not implemented error!");
end if
end function
public function serialize(serializer : ISerializer) : string
return serializer.serialize(content.clone())
end function
private content : Dictionary<int, string>
to:
public content : Dictionary<int, string>
so that plugins can directly manipulate and save the shopping cart.Tags
Software EngineeringScore Distribution
0-33% | |
---|---|
34-66% | |
67-100% |
Would you like to see our other questions?
We have 850+ premium hand-crafted questions for 50+ job skills and 15+ coding languages. We prefer questions with small samples of actual work over academic problems or brain teasers.
Visit our question libraryPrivate Concierge
Send us an email with an explanation of your testing needs and a list of candidates. We will create an appropriate test, invite your candidates, review their results, and send you a detailed report.
Contact Private ConciergeWould you like to see our tests? The following tests contain Software Engineering related questions:
On the TestDome Blog
Screening Applicants: The Good, the Bad and the Ugly
Since we’re all biased and we use incorrect proxies, why not just outsource hiring to experts or recruitment agencies? After all, they’ve been screening people for many years, so they must know how to do it right?
Not really. I was surprised to discover that many experts disagree with each other. Everybody praises their pet method and criticizes the others. Many of these methods look legitimate, but are based on...