views:

72

answers:

1

I've been working on an API (which wraps a web-service of sorts) for a while now, and its just about feature complete.

I initially designed this API to be lazy/delay-loaded throughout; which makes perfect sense if you're only interested in a small subset of the available data given the latency inherent in consuming a web-service. However, I failed to consider a few use cases where eager loading would be much easier on a consumer of the API.

So, my question is: How would you like to see an API that is predominately lazy-loading expose a mechanism for getting eagerly-loaded versions of classes?

I'm leaning towards an explicit cast, but something along the lines of Eager.AsEager(SomeDelayLoadingObject) also seems natural if more verbose.

A: 

What I actually ended up doing was creating a shallow copy of the classes I wanted to be eagerly loaded, classes with no functional code but with all the same properties.

I then defined two implicit casts, from lazy->eager and eager->lazy. Both casts copied all properties; thereby triggering any loading if it was needed.

While I don't think this is a perfect solution, it makes eagerly loading simply changing types; no code changes are needed.

Kevin Montrose