Let’s say we have a class called A and another one called B.
and we want to have a conversion method that converts A to B.
In the software architecture point of view, which one is preferred?
- write
A.export() - write
B.import() - write a converter class, i.e.
convert(A, B)orConvert(A)or …
if the language matters, I’m using C++
It entirely depends on how you intend to use it, but in many cases, the cleanest way to do this is to implement a converting constructor:
(of course, you could implement a converting constructor for converting from
AtoB, as well)