设计模式 - 裝飾者模式如何選擇?iOS開發中什麼地方體現了裝飾者模式的身影?
PHP中文网
PHP中文网 2017-04-17 13:25:53
0
2
358

今天學習了設計模式中的裝飾者模式?不過對於我們何時使用裝飾者模式不是很清楚?請指教

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
阿神
  1. Want to add tasks to a single object in a dynamic and transparent manner without affecting other objects
  2. 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
  3. 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~

Ty80
  1. Need to extend the functionality of a class or add additional responsibilities to a class.
  2. You need to dynamically add functions to an object, and these functions can be dynamically revoked.
  3. 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.
  4. 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. . . .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!