Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Using IXmlSerializable

There are some things to take into considerationsome things to take into consideration when implementing this interface and you should check to see if your intended use is compatible with this. Big advantage of this approach is that you can serialize what are otherwise private or protected fields, and the fairly straightforward usage of serialization (method on the object itself). This approach might validate SRP depending on the nature of the serialized object.

Using a Serializer

Using a serializer allows you to take advantage of DI (Dependency Injection), so you can have re-usable XML serialization classes injected with DI. This makes writing tests a lot simpler as using new to create new objects makes it significantly harder to write tests(1) Disadvantage is that you have to carry around serializers to use thoughout your code and will probably need some degree of wiring code to obtain the correct serializer for a given object.

In the end, it boils down to what advantages matter more and what disadvantages would seriously hamper your development.

  1. If two objects contain the same type of child object, the serialization of that object can be split off into a separate class with separate tests. The tests on the parent serializer would only need to verify the child serializers are called. Without DI you'd probably need to duplicate the tests for the children across the parents.

Using IXmlSerializable

There are some things to take into consideration when implementing this interface and you should check to see if your intended use is compatible with this. Big advantage of this approach is that you can serialize what are otherwise private or protected fields, and the fairly straightforward usage of serialization (method on the object itself). This approach might validate SRP depending on the nature of the serialized object.

Using a Serializer

Using a serializer allows you to take advantage of DI (Dependency Injection), so you can have re-usable XML serialization classes injected with DI. This makes writing tests a lot simpler as using new to create new objects makes it significantly harder to write tests(1) Disadvantage is that you have to carry around serializers to use thoughout your code and will probably need some degree of wiring code to obtain the correct serializer for a given object.

In the end, it boils down to what advantages matter more and what disadvantages would seriously hamper your development.

  1. If two objects contain the same type of child object, the serialization of that object can be split off into a separate class with separate tests. The tests on the parent serializer would only need to verify the child serializers are called. Without DI you'd probably need to duplicate the tests for the children across the parents.

Using IXmlSerializable

There are some things to take into consideration when implementing this interface and you should check to see if your intended use is compatible with this. Big advantage of this approach is that you can serialize what are otherwise private or protected fields, and the fairly straightforward usage of serialization (method on the object itself). This approach might validate SRP depending on the nature of the serialized object.

Using a Serializer

Using a serializer allows you to take advantage of DI (Dependency Injection), so you can have re-usable XML serialization classes injected with DI. This makes writing tests a lot simpler as using new to create new objects makes it significantly harder to write tests(1) Disadvantage is that you have to carry around serializers to use thoughout your code and will probably need some degree of wiring code to obtain the correct serializer for a given object.

In the end, it boils down to what advantages matter more and what disadvantages would seriously hamper your development.

  1. If two objects contain the same type of child object, the serialization of that object can be split off into a separate class with separate tests. The tests on the parent serializer would only need to verify the child serializers are called. Without DI you'd probably need to duplicate the tests for the children across the parents.
Source Link
JDT
  • 6.4k
  • 21
  • 33

Using IXmlSerializable

There are some things to take into consideration when implementing this interface and you should check to see if your intended use is compatible with this. Big advantage of this approach is that you can serialize what are otherwise private or protected fields, and the fairly straightforward usage of serialization (method on the object itself). This approach might validate SRP depending on the nature of the serialized object.

Using a Serializer

Using a serializer allows you to take advantage of DI (Dependency Injection), so you can have re-usable XML serialization classes injected with DI. This makes writing tests a lot simpler as using new to create new objects makes it significantly harder to write tests(1) Disadvantage is that you have to carry around serializers to use thoughout your code and will probably need some degree of wiring code to obtain the correct serializer for a given object.

In the end, it boils down to what advantages matter more and what disadvantages would seriously hamper your development.

  1. If two objects contain the same type of child object, the serialization of that object can be split off into a separate class with separate tests. The tests on the parent serializer would only need to verify the child serializers are called. Without DI you'd probably need to duplicate the tests for the children across the parents.