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 now wants to have the possibility for allowing plugins 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 extensibility.

(Select all acceptable answers.)

class JsonSerializer
Should be changed to:
class JsonSerializer inherits ISerializer
Add interface definition:
interface ISerializer
  public function serialize(Dictionary<int, string>) : string
end interface
Add Enum definition that will be extended as new plugins will be added (e.g., to add XML serialization):
enumeration SerializerType
  Json,
  Xml
end enumeration
Change ShoppingCart's serialize implementation to one like below (e.g., to add XML serialization):
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
Change ShoppingCart's serialize implementation to:
public function serialize(serializer : ISerializer) : string
  return serializer.serialize(content.clone())
end function
Change ShoppingCart's data member from:
private content : Dictionary<int, string>
to:
public content : Dictionary<int, string>
so that plugins can directly manipulate and save the shopping cart.
   

Tags
Software Engineering OOP Public New
Easy

5min

Score Distribution
Not enough data for chart
Would you like to see our other questions?

We have 500+ premium hand-crafted questions for 30+ job skills and 10+ coding language. We prefer questions with small samples of actual work over academic problems or brain teasers.

Visit our question library

Private 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.


Would 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...