Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design pattern in iOS as decorator pattern

I have a question about design patterns in iOS.

I have a UIView with a xib file. We can consider this view as a view-template.

Now we can consider several views (subclass, for example) that specify the behavior of the view template (different methods, animation, etc.).

Is there something that may be fine in my case? Some design pattern? For example, the Decorator design pattern?

like image 448
Safari Avatar asked May 19 '14 14:05

Safari


1 Answers

The Decorator Design Pattern

The Decorator design pattern attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. As does subclassing, adaptation of the Decorator pattern allows you to incorporate new behavior without modifying existing code. Decorators wrap an object of the class whose behavior they extend. They implement the same interface as the object they wrap and add their own behavior either before or after delegating a task to the wrapped object. The Decorator pattern expresses the design principle that classes should be open to extension but closed to modification.

There are several patterns related to polymorphism that can be used within Swift, but two key ones you’ll see often are the Decorator and Adapter patterns. These are implemented using the language keywords extension and protocol respectively.

The primary example of the Decorator pattern in Swift is when you create an extension. In Objective-C, there is a similar mechanism with class categories.

iOS Design Pattern

http://en.wikipedia.org/wiki/Decorator_pattern

http://zubairraihan.blogspot.in/2013/02/decorator-design-pattern-in-objective-c.html

http://techrantnz.blogspot.in/2011/08/decorator-builder-design-pattern-in.html

intro-object-oriented-design-swift-part-2

like image 79
Pawan Rai Avatar answered Sep 30 '22 16:09

Pawan Rai