- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
DTO in Scala
Wed, 2009-04-01, 18:39
Does Data Transfer Object pattern make sense in Scala? Are there
better options? Is there a kind of BeansUtils/Dozer API for mapping
scala objects?
Thanks in advance.
- Andrés
Fri, 2009-04-03, 19:47
#2
Re: DTO in Scala
Thanks four your response, Kristian. I like the trait approach, but
since there is not automatic convertion between traits, a convertion
method (your implicit function) must be defined to perform the
mapping. Deep mapping is an additional issue.
Regards.
- Andrés
2009/4/1 Kristian Domagala :
> I haven't done anything specifically like this in Scala, but having returned
> recently to Java on a project that uses the DTO "pattern", I keep thinking
> that traits would make my life a lot simpler. The idea in my head is to have
> a trait that describes the common interface between the DTO object and
> domain model, which provides the implementation of the accessors. The domain
> class would extend the trait with the domain logic, and the DTO class would
> extend the trait with no further implementation (unless the DTOs were used
> in both directions, in which case you might want to have DTO specific
> mutators). You could have an implicit function(s) to convert between the
> two.
>
> As I said, I haven't actually done this in Scala, so I'm not sure how well
> it would work in practice. I'm not even sure that if I was doing my current
> project in Scala that there would even be an explicit notion of DTOs; my
> thoughts above are only centered on the direct translation of that aspect of
> the code.
>
> Cheers,
> Kristian.
>
> On Thu, Apr 2, 2009 at 3:38 AM, Andrés Testi
> wrote:
>>
>> Does Data Transfer Object pattern make sense in Scala? Are there
>> better options? Is there a kind of BeansUtils/Dozer API for mapping
>> scala objects?
>> Thanks in advance.
>>
>> - Andrés
>
>
Mon, 2009-04-06, 00:47
#3
Re: DTO in Scala
Andrés,
Yes, you're right on both accounts. I'm not doing deep mapping on my current project, so I didn't consider that. As for automatic conversion, I still have a gut feeling that there would be a minimal way around it using composition (UML) & delegation in the domain model, but I haven't had an opportunity to work through and verify it.
Cheers,
Kristian.
On Sat, Apr 4, 2009 at 4:36 AM, Andrés Testi <andres.a.testi@gmail.com> wrote:
Yes, you're right on both accounts. I'm not doing deep mapping on my current project, so I didn't consider that. As for automatic conversion, I still have a gut feeling that there would be a minimal way around it using composition (UML) & delegation in the domain model, but I haven't had an opportunity to work through and verify it.
Cheers,
Kristian.
On Sat, Apr 4, 2009 at 4:36 AM, Andrés Testi <andres.a.testi@gmail.com> wrote:
Thanks four your response, Kristian. I like the trait approach, but
since there is not automatic convertion between traits, a convertion
method (your implicit function) must be defined to perform the
mapping. Deep mapping is an additional issue.
Regards.
- Andrés
2009/4/1 Kristian Domagala <kristian.domagala@gmail.com>:
> I haven't done anything specifically like this in Scala, but having returned
> recently to Java on a project that uses the DTO "pattern", I keep thinking
> that traits would make my life a lot simpler. The idea in my head is to have
> a trait that describes the common interface between the DTO object and
> domain model, which provides the implementation of the accessors. The domain
> class would extend the trait with the domain logic, and the DTO class would
> extend the trait with no further implementation (unless the DTOs were used
> in both directions, in which case you might want to have DTO specific
> mutators). You could have an implicit function(s) to convert between the
> two.
>
> As I said, I haven't actually done this in Scala, so I'm not sure how well
> it would work in practice. I'm not even sure that if I was doing my current
> project in Scala that there would even be an explicit notion of DTOs; my
> thoughts above are only centered on the direct translation of that aspect of
> the code.
>
> Cheers,
> Kristian.
>
> On Thu, Apr 2, 2009 at 3:38 AM, Andrés Testi <andres.a.testi@gmail.com>
> wrote:
>>
>> Does Data Transfer Object pattern make sense in Scala? Are there
>> better options? Is there a kind of BeansUtils/Dozer API for mapping
>> scala objects?
>> Thanks in advance.
>>
>> - Andrés
>
>
As I said, I haven't actually done this in Scala, so I'm not sure how well it would work in practice. I'm not even sure that if I was doing my current project in Scala that there would even be an explicit notion of DTOs; my thoughts above are only centered on the direct translation of that aspect of the code.
Cheers,
Kristian.
On Thu, Apr 2, 2009 at 3:38 AM, Andrés Testi <andres.a.testi@gmail.com> wrote: