This kata is intended to help one practice the DRY principle (Don’t Repeat Yourself). You can read more about DRY here.
A few notes:
- After completing a step in the Kata and before moving on to the next, take the time to make sure your code’s duplication ≤ 0
- For the sake of focus, you may ignore matters of character escaping, encoding, error handling, object graph cycles and the likes
- Our focus is on reducing duplication, it is not finishing the kata
In this Kata, our goal is to implement 2 simple object serializers. One serializer is to XML, the other is to JSON.
- Support serializing a class without any members
- To XML: EmptyClass –> <EmptyClass></EmptyClass>
- To JSON: EmptyClass –> {}
- Add support for serializing a class’ integer members
- To XML: IntClass(a=1, b=2) –> <IntClass><a>1</a><b>2</b></IntClass>
- To JSON: IntClass(a=1, b=2) –> { “a”: 1, “b”: 2 }
- Add support for serializing a class’ string members
- To XML: StrClass(a=“first”, b=“second”) –> <StrClass><a>first</a><b>second</b></StrClass>
- To JSON: StrClass(a=“first”, b=“second”) –> { “a”: “first”, “b”: “second” }
- Add support for serializing a class’ other class members
- To XML: CompositeClass(inner=(a=1)) –> <CompositeClass><inner><a>1</a></inner></CompositeClass>
- To JSON: CompositeClass(inner=(a=1)) –> { “inner”: { “a”: 1 } }
If you found this interesting subscribe to my feed and follow me on twitter!