views:

49

answers:

1

I have an example where a protocol would be ideal except for the fact that there is a subset of common state and a few methods that I want to share amongst all implementers of the protocol. This would suggest class sub-classing rather then protocol-ing. I am leary of using sub-classing do primarily to its inflexibility and general loose coupling.

Can someone suggest an clean solution to this example?

Thanks in advance.

-Doug

+2  A: 

Perhaps a combination of protocol and composition would be cleaner. Where the protocol defines the common functionality, but reference a common data object that maintains the shared state.

This solution has worked well for me in some specific cases, hard to tell if this would accomplish what you want.

MarkPowell
Thanks. Funny, I arrived at your solution about ten minutes ago and it should work just fine. Cheers.
dugla