Want to add tasks to a single object in a dynamic and transparent manner without affecting other objects
I want to extend the behavior of a class, but I can’t. The class definition may be hidden and cannot be subclassed; or, the extension of each behavior of the class will generate a large number of subclasses to support this combination of functions
Extensions to class responsibilities are optional.
This is explained in Objective-c Programming~
Another: The book "Design Patterns" says that decoration mode: dynamically adds some additional responsibilities to an object. In terms of extended functions, decoration is more flexible than generating subclasses.
Note: This design pattern will be used when creating image filters for UIImage in iOS development~
Need to extend the functionality of a class or add additional responsibilities to a class.
You need to dynamically add functions to an object, and these functions can be dynamically revoked.
It is necessary to add a very large number of functions generated by the permutation and combination of some basic functions, making the inheritance relationship unrealistic.
When the method of generating subclasses cannot be used for expansion. In one case, there may be a large number of independent extensions, and a large number of subclasses will be generated to support each combination, causing the number of subclasses to explode. Another case could be because the class definition is hidden, or the class definition cannot be used to generate subclasses.
The above content is reproduced from Baidu Encyclopedia. . . .
Extensions to class responsibilities are optional.
This is explained in Objective-c Programming~
Another: The book "Design Patterns" says that decoration mode: dynamically adds some additional responsibilities to an object. In terms of extended functions, decoration is more flexible than generating subclasses.
Note: This design pattern will be used when creating image filters for UIImage in iOS development~
The above content is reproduced from Baidu Encyclopedia. . . .