On Dec 12, 2012, at 5:24 AM, Andreas Grosam <agro...@onlinehome.de> wrote:

> And, it can be a block as well, where the block is responsible to feed the 
> consumer (the id<RXMultipartFormdataPart>) with data when it has bytes 
> available when the request is active.
> You can do this with the same method, same API. Well, it MUST, otherwise the 
> number of combinations of the various types yielding different methods, would 
> explode.


You don’t have to do it that way. An alternative is to make a class that can 
wrap any of those objects and remembers which one it is; then you can call 
[Parameter parameterWithString:] or +parameterWithNumber: or 
+parameterWithBlock: or whatever, and have methods on Parameter that can tell 
you what sort of object it was created with. 

(NSValue has a very similar design — note that it can store a large number of 
different types without having to use a separate class for each one, or 
requiring the caller to use -isKindOfClass: to find out if a value is a point 
or a rect or a double.)

If you don’t want to do that, you should at least make a wrapper class around a 
block, like RXBlock. Basically just a simple class whose instances hold onto a 
block pointer. Then you can check whether a parameter is an instance of 
RXBlock, and if it is, get the block value from it. It’s only a bit more work 
for the client who has to call an RXBlock factory method instead of just 
passing in a block literal directly.

—Jens
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to