What's the name of the design pattern that makes a part of a class reusable.
I'm doing Objective-C for iOS, say I have several UIViewControllers.
Some of these view controllers will have a particular feature that I developed and I want to be able to reuse it easily.
The feature in q开发者_如何学Cuestion consists of two methods that use an instance variable of the UIViewController.
In Objective-C, it's similar to a category but that could be used theoretically with any kind of class.
I know this is not very clear but any help is appreciated.
You might be able to implement your functionality as a decorator using the decorator pattern.
You can subclass UIViewController
, creating a custom UIViewController
(say "sub1"). Then all of the UIViewController
s that need that functionality can subclass sub1
. This way you can easily reuse the code written once for sub1
simply using inheritance.
...The feature in question consists of two methods... that could be used theoretically with any kind of class.
well without knowing more details I'd say Extract Class looks generally worth considering. For particular use cases, more specialized ones might be better fit than that (Strategy, Specification etc etc etc)
精彩评论