Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-07-2010, 10:39 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Long Beach, CA
Posts: 612
bytor99999 is on a distinguished road
Send a message via AIM to bytor99999 Send a message via Yahoo to bytor99999
Default Delegation is the Template Method design pattern

OK, this is more a statement than a question.

Delegation had been giving me a little problem when trying to create one myself, rather than the common implementing the TableView delegate methods.

So, after reading and examining, this is the Template Method design pattern. So why did they change the name to delegation. Just to confuse those who already know design patterns? Just to be different?

The one thing that is a bit different is in the Template Method pattern your parent class is abstract and you extend it in your subclass, whereas in Apple's delegate world there is no inheritance here. so one class has a reference to another and delegates to it, which takes from the Gang of Four Delegation pattern. But it resembles the Template Method pattern more. The Hollywood Principle, "don't call us, we'll call you"

Mark
__________________
Perfect World Programming LLC
http://www.perfectworldprogramming.com

Please check out my apps.

TubeOrganizer
http://www.spritzlerapps.com/tube-organizer.html

Paper Clips
http://spritzlerapps.weebly.com/paper-clips.html
bytor99999 is offline   Reply With Quote
Old 08-07-2010, 10:42 AM   #2 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Long Beach, CA
Posts: 612
bytor99999 is on a distinguished road
Send a message via AIM to bytor99999 Send a message via Yahoo to bytor99999
Default

And the formal version of the delegate pattern here in Apple has you create a protocol which is like an interface/abstract class, then you are basically subclassing.

Mark
__________________
Perfect World Programming LLC
http://www.perfectworldprogramming.com

Please check out my apps.

TubeOrganizer
http://www.spritzlerapps.com/tube-organizer.html

Paper Clips
http://spritzlerapps.weebly.com/paper-clips.html
bytor99999 is offline   Reply With Quote
Old 08-07-2010, 07:53 PM   #3 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by bytor99999 View Post
OK, this is more a statement than a question.

Delegation had been giving me a little problem when trying to create one myself, rather than the common implementing the TableView delegate methods.

So, after reading and examining, this is the Template Method design pattern. So why did they change the name to delegation. Just to confuse those who already know design patterns? Just to be different?

Sorry, I disagree. delegation is a different design pattern than the Template Method design pattern. In Template Method, you create methods that you then override in your subclasses to fine-tune the behavior of the classes.

Delegation is different. Delegation allows one object (the delegate) to modify the behavior of another object. It is possible to assign different delegates to different instances of an object at runtime, which can cause identical objects with different delegate objects to behave differently.

Delegates are also very useful for things like async operations. You create an object to handle an async process, and assign a delegate that gets notified at key points in the async process.

An object is only aquatinted with it's delegate, but in the template method, the abstract object and its subclass are aggregated.

Apple's delegation design pattern IS the gang of 4 delegation pattern. Why do you say it's closer to the template method pattern?
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 08-08-2010, 10:15 AM   #4 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Long Beach, CA
Posts: 612
bytor99999 is on a distinguished road
Send a message via AIM to bytor99999 Send a message via Yahoo to bytor99999
Default

True, I said in my post that it isn't 100% the Gang of Four Template Method patter. But I was reading documentation on Delegation and they said that the formal version has a protocol, which is like an interface or abstract class that your class that implements it is like a subclass.

I have definitely found that objective-c is very different in its OO principle usage. Calling the .h file @interface, when a protocol is actually like an interface.

Anyway, it just seems to me more towards Template Method than Delegate design pattern. I do agree that it isn't exactly the Template Method with true subclasses implementing the difference, and that any class can be a delegate of another. But like subclassing, you can only have one. meaning I can only assign one object as the delegate to another object.

Mark
__________________
Perfect World Programming LLC
http://www.perfectworldprogramming.com

Please check out my apps.

TubeOrganizer
http://www.spritzlerapps.com/tube-organizer.html

Paper Clips
http://spritzlerapps.weebly.com/paper-clips.html
bytor99999 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 309
9 members and 300 guests
arash5500, gordo26, HemiMG, linkmx, mediaspree, nobstudio, Objective Zero, stanny, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:29 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0