Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
Delegation is not finished code per se, but a design pattern. Let’s talk about what a design pattern is and where delegates fit in.
-
0:00
[SOUND] Hi, I'm Pasan and welcome to this
-
0:05
course on delegation at Treehouse.
-
0:09
In software development since people have been at it for
-
0:13
a fairly long time now, we've run into some common problems.
-
0:17
There are lots of these kinds of problems.
-
0:19
How to create flexible objects.
-
0:22
How to communicate between objects without tight coupling and
-
0:25
how to facilitate relationships between objects.
-
0:29
During the early days of software development,
-
0:32
engineers figured out their own ways around these problems.
-
0:36
But as it became evident that these problems occurred in almost all domains
-
0:40
and weren't specific to the task at hand,
-
0:43
more general purpose solutions began to emerge.
-
0:47
Today we call these solutions design patterns.
-
0:51
A design pattern is a general reusable solution to commonly occurring
-
0:56
problems within a given context, regardless of a particular domain.
-
1:02
Design patterns aren't finished code per se.
-
1:05
They aren't something you can plug into your project and be done with.
-
1:08
Instead they're templates for
-
1:10
solving problems that occur in many different situations.
-
1:14
A design pattern makes it easier to reuse successful software development
-
1:19
architectures and solve problems without having to reinvent the wheel.
-
1:24
As I mentioned there are different problems for
-
1:26
which there are different design patterns.
-
1:29
In this course we're going to focus on just one that is very prevalent in our
-
1:33
domain and good to understand before we run into it when we use various IOS APIs.
-
1:40
That pattern is the delegate pattern.
-
1:43
The delegate pattern is a variation of a design pattern
-
1:47
that is more commonly called the decorator pattern.
-
1:50
The decorator pattern is a structural pattern, that is it is a pattern that is
-
1:54
focused on how we can compose objects to form larger structures.
-
2:00
The decorator pattern in particular is concerned with how we can add
-
2:04
responsibilities to an object dynamically.
-
2:07
That is at runtime rather than statically at compile time.
-
2:12
Before we get into any of this though, I'd like to walk us through an example and
-
2:17
try to solve it without any knowledge of delegation.
-
2:20
And you will see that the resulting code is not as flexible as we'd like it to be
-
2:25
or reusable.
-
2:26
This should help illustrate the problem we're trying to solve and
-
2:29
show how delegation makes it much easier.
You need to sign up for Treehouse in order to download course files.
Sign up