All language subtitles for 010 Decorator Pattern_en

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian Download
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:04,640 --> 00:00:12,380 Now, suppose that we want to have our rage ability, some sort of variant, we want to have a delayed 2 00:00:12,380 --> 00:00:13,220 rage ability. 3 00:00:13,470 --> 00:00:20,570 Now the obvious way to implement this is to create a subclass of the reachability and add in any of 4 00:00:20,570 --> 00:00:22,310 the extra functionality that we want there. 5 00:00:22,640 --> 00:00:28,550 But suppose delaying something is quite a common piece of functionality, and we want to be able to 6 00:00:28,550 --> 00:00:33,500 delay not only the rage ability, but maybe the heal ability, the fireball ability or any other abilities 7 00:00:33,500 --> 00:00:34,790 that we can think of later on. 8 00:00:35,150 --> 00:00:41,060 Or alternatively, we want to apply different modifiers like a repeating modifier to change the way 9 00:00:41,060 --> 00:00:44,450 the heal ability heals over time or something like that. 10 00:00:44,900 --> 00:00:51,680 Now we can easily make this more modular by saying, let's implement a delaying decorator. 11 00:00:51,680 --> 00:00:55,520 So the decorator would essentially be another type of ability. 12 00:00:55,520 --> 00:00:57,920 It would have its own implementation of use. 13 00:00:58,280 --> 00:01:05,840 But instead of entirely creating all of its own rage functionality there or inheriting from rage, it 14 00:01:05,840 --> 00:01:07,360 would use composition. 15 00:01:07,370 --> 00:01:10,410 It would have an ability that it delays. 16 00:01:10,910 --> 00:01:16,910 That is a property, a private property, and that would be an instance of the AI ability. 17 00:01:16,910 --> 00:01:19,700 So essentially you could slot anything in there. 18 00:01:19,730 --> 00:01:23,960 You could delay any other ability, including and this is kind of interesting. 19 00:01:23,990 --> 00:01:29,030 Another delay decorator so you could delay a delaying decorator and wrap those indefinitely. 20 00:01:29,240 --> 00:01:34,310 So what you would get is instead of having the ability run a pointing directly to an instance of the 21 00:01:34,310 --> 00:01:38,570 rage ability, you would introduce a delaying decorator in the mix. 22 00:01:38,570 --> 00:01:43,400 So the ability runner would point to an instance of the delaying decorator, which itself would point 23 00:01:43,400 --> 00:01:44,630 to the rage ability. 24 00:01:44,630 --> 00:01:52,460 And that allows us to decorate or augment the functionality of that ability that is being wrapped. 25 00:01:53,180 --> 00:01:59,510 So if we changed out the names, what we've got here is the classic formulation of the decorator pattern 26 00:02:00,050 --> 00:02:05,600 where we've got components and operations instead of abilities and use. 27 00:02:05,990 --> 00:02:13,040 And the decorator is something that contains one of the components and has its own operation that overrides 28 00:02:13,040 --> 00:02:16,530 the operation of whatever the concrete component might be. 29 00:02:16,580 --> 00:02:21,800 And you often see this formulation as well, where we take the decorator to be an abstract class that 30 00:02:21,800 --> 00:02:27,310 inherits from the component interface and the concrete decorator often inherits from that. 31 00:02:27,320 --> 00:02:28,460 We're not going to do it this way. 32 00:02:28,460 --> 00:02:29,930 That's a little bit more complicated. 33 00:02:30,380 --> 00:02:34,100 So let's go and see how we can implement a decorator like this now. 34 00:02:34,100 --> 00:02:38,510 If you feel confident and want to give this a stamp for yourself and do pause the video and see if you 35 00:02:38,510 --> 00:02:42,140 can implement this kind of class layout for yourself. 36 00:02:42,440 --> 00:02:44,480 If not, follow along with me. 37 00:02:45,140 --> 00:02:50,540 So what we're going to do is we're going to create underneath the ability interface. 38 00:02:50,780 --> 00:02:56,420 I'm going to create a new public class called the delayed decorator. 39 00:02:57,680 --> 00:03:00,470 And it's going to inherit AI ability. 40 00:03:00,830 --> 00:03:07,340 And for sake of simplicity, I'm going to remove mono behavior from the rage ability and the scripts 41 00:03:07,340 --> 00:03:07,730 will object. 42 00:03:07,730 --> 00:03:10,040 So they are just pure C-sharp classes. 43 00:03:10,190 --> 00:03:15,530 Then I'm going to implement the interface because that will make it a public implementation. 44 00:03:15,560 --> 00:03:16,520 So there we go. 45 00:03:16,520 --> 00:03:17,390 We've got a using method. 46 00:03:17,390 --> 00:03:23,210 It's not implemented yet because in order to implement it, we need the ramped ability a reference to 47 00:03:23,210 --> 00:03:23,450 that. 48 00:03:23,450 --> 00:03:28,160 So we're going to have a private variable in here that's going to be of type ability, and I'm going 49 00:03:28,160 --> 00:03:30,290 to call it the rapt ability. 50 00:03:30,950 --> 00:03:37,010 And that's not going to be set up yet because we need to set that up when we construct this decorator. 51 00:03:37,190 --> 00:03:42,580 But we can now implement the use function that we've inherited here. 52 00:03:42,920 --> 00:03:50,000 We're going to do that by calling to the ramped ability to use and we can do on the line before it to 53 00:03:50,000 --> 00:03:52,940 do some delaying functionality. 54 00:03:52,970 --> 00:03:58,250 So here we've not actually got an implementation that is really workable in the game, but you get the 55 00:03:58,250 --> 00:03:58,730 idea. 56 00:03:58,940 --> 00:04:06,110 The idea here is we do some other piece of code before we call to our wrapped abilities, use functionality. 57 00:04:06,230 --> 00:04:11,450 Now, in order to set this up, we need a constructor that will actually take in the ability we're supposed 58 00:04:11,450 --> 00:04:11,930 to wrap. 59 00:04:12,200 --> 00:04:17,750 You can easily do this in a voice code by doing controlled dots when you've got your cursor on that 60 00:04:17,750 --> 00:04:19,579 private member variable. 61 00:04:19,790 --> 00:04:25,730 So we're going to do a control dart and do generate constructor for delayed decorator. 62 00:04:26,000 --> 00:04:31,430 And that's going to create as a public constructor that takes in a ramped ability and sets it to the 63 00:04:31,490 --> 00:04:32,660 private property. 64 00:04:32,720 --> 00:04:41,030 So your challenge here is going to be to go ahead and construct a delayed decorator instead of that 65 00:04:41,030 --> 00:04:47,740 rage ability that we're doing in our ability run to make a delayed decorator to wrap that rage ability, 66 00:04:47,750 --> 00:04:49,100 pause the video and have a go. 67 00:04:52,320 --> 00:04:57,360 OK, welcome back, so I'm just going to put this new rage ability on a new line because what we want 68 00:04:57,360 --> 00:05:02,040 to do is set the current ability to a new delayed decorator. 69 00:05:02,490 --> 00:05:06,630 And we know that the delayed decorator takes in an eye ability itself. 70 00:05:06,640 --> 00:05:15,180 So what we can pass in is the new rage ability as the parameter to the delayed decorator constructor. 71 00:05:15,570 --> 00:05:22,650 So then essentially what we've ended up with is a current ability, pointing to a delayed decorator, 72 00:05:22,650 --> 00:05:27,510 which is pointing to the rage ability, which is exactly what we had in the diagram. 73 00:05:27,810 --> 00:05:35,130 So hopefully that elucidates how the wrapper the decorator pattern is working here now. 74 00:05:35,130 --> 00:05:38,970 You could swap this out for mono behaviors, or you could swap it out. 75 00:05:38,970 --> 00:05:45,630 The scripts with objects that key that you'd have to work out here is that you would need to point to 76 00:05:45,630 --> 00:05:53,310 either a mono behavior subclass here or a script pull objects subclass in IE ability in order for this 77 00:05:53,310 --> 00:05:56,010 to work, because you'd need to make it a serialized field. 78 00:05:56,010 --> 00:05:59,280 So I'll just sketch out what this would roughly look like. 79 00:05:59,280 --> 00:06:01,080 This isn't going to be a complete solution. 80 00:06:01,350 --> 00:06:09,300 But for example, you would have a public abstract class that would be your base ability. 81 00:06:09,840 --> 00:06:14,970 So and that would inherit from the script full object and from my ability. 82 00:06:15,390 --> 00:06:24,000 And it would needs to abstractly implement the use method like so and then in anything that you want 83 00:06:24,000 --> 00:06:29,910 to make a script for object, you would need to inherit instead it from liability you'd inherit from 84 00:06:29,910 --> 00:06:30,720 the base ability. 85 00:06:30,840 --> 00:06:38,550 So and then instead of having a constructor here, you would set up the link to the wrapped ability 86 00:06:38,910 --> 00:06:41,310 as a pointer to a base ability. 87 00:06:41,430 --> 00:06:46,830 So and have it as a serialized field, not a serialized reference. 88 00:06:46,830 --> 00:06:47,490 Like so. 89 00:06:47,520 --> 00:06:49,980 And then some syntactic changes here. 90 00:06:49,980 --> 00:06:57,600 You'd have to have public override because we're using that abstract class and that just needs a syntactic 91 00:06:57,600 --> 00:06:58,260 difference. 92 00:06:58,410 --> 00:07:00,900 So you would just do that instead, and that mostly works. 93 00:07:00,900 --> 00:07:05,520 You'll need to also pull these out into separate files and have a create asset menu. 94 00:07:05,520 --> 00:07:08,670 And all that good stuff that you're used to from using scripts will object. 95 00:07:08,940 --> 00:07:12,810 But that's the rough outline of how this would work with scripts for objects. 96 00:07:12,930 --> 00:07:18,750 So I'm just going to go ahead and undo all of that to leave our code in a compiler state where we were 97 00:07:18,750 --> 00:07:20,970 just using pure c sharp objects. 98 00:07:21,210 --> 00:07:26,490 And in the next lecture, we're going to build upon that when we're going to look at the composite pattern, 99 00:07:26,580 --> 00:07:33,240 which is related to all of this decorators and strategy pattern family. 100 00:07:33,360 --> 00:07:33,990 I'll see you there. 10704

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.