Having domain objects implement EntityProxy - bad idea?

62 views
Skip to first unread message

Ryan McFall

unread,
Jun 11, 2012, 3:35:02 PM6/11/12
to Google Web Toolkit
One of the things I don't like about the design of the RequestFactory
is the fact that client-side proxies need to extend EntityProxy; I
think I understand why this is needed, but it makes it more difficult
to write code that can operate on both proxies and actual domain
objects.

One way of getting around this is to have the domain objects implement
the proxy interface. This means that the domain objects must
implement EntityProxy, giving a stableId method that shouldn't
actually be called, but allows utility code to treat proxies and
domain objects in the same way.

Before going down this route, I'm wondering if there are reasons it
won't work that I haven't thought about.

Thanks!
Ryan

jajang nurjaman

unread,
Jun 11, 2012, 5:03:09 PM6/11/12
to google-we...@googlegroups.com
Okay thanks mr..at http://globalcyber.cu.cc
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-web-tool...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>

Thomas Broyer

unread,
Jun 12, 2012, 2:53:55 AM6/12/12
to google-we...@googlegroups.com
I can't see any reason it wouldn't work, but I think you'd rather extract an interface, implemented by your domain object, and extended by your proxy (in addition to EntityProxy).

interface Domain { /* getters and setters */ }

class DomainImpl implements Domain { … }

interface DomainProxy extends Domain, EntityProxy { … }

In case you were wondering, this approach has been proven to work.
One exception is currently if your Domain interface references another interface (as opposed to "simple value types"), where you'd face http://code.google.com/p/google-web-toolkit/issues/detail?id=5926
This issue will be fixed in GWT 2.5.1, which we expect to release by the end of the summer.

Ryan McFall

unread,
Jun 12, 2012, 9:26:42 AM6/12/12
to google-we...@googlegroups.com
Wow, I'm embarrassed to say that I have always assumed that an interface can only extend a single interface, because that's the way that it works for classes.  There's no reason it should be that way, though, and it makes life a lot easier to know that it's possible.  I would have done it this way originally over a year ago had I known this!
 
Thanks,
Ryan
Reply all
Reply to author
Forward
0 new messages