Transcript from the "Exercise 4" Lesson
>> Kyle Simpson: Rather than belaboring some time because we've still got async to get into, I wanna give you as homework exercise 4. Just real briefly to orient you, it calls for you to create a widget and a button as a parent and child class. You first use the prototype style and model it as a parent child class sort of a thing, so that you can instantiate buttons on your page like you're instantiating UI widgets.
[00:00:30] Then it asks you to go back and rethink about it in terms of Oluv style and in terms of delegation, where rather than having a parent and child, you have two peer objects. You have a general widget utility object, and you have a more task specific button object.
[00:00:45] So that exercise has both the open files for you to work on as well as the the fixed version. You end up at the end of that exercise with a nice side-by-side comparison between class style code and Oluv style code, and it lets you further decide which one works for you.
>> Speaker 1: There's a question online from James L. Are there any circumstances in which you mix two of these patterns as in use Oluv to delegate a module or visa versa?
>> Kyle Simpson: Yes I have done that before, doesn't happen very often but I have done that before. You have to be a little bit careful because delegation can sometimes be counter productive to the encapsulation that you're trying to do with modules and visa versa.
[00:01:29] You have to be a little bit careful with it but I have done delegation between two encapsulated modules before.
>> Speaker 1: Is there a generalization you can make about what instances you would do that in?
>> Kyle Simpson: Probably not. [CROSSTALK]
>> Speaker 1: Some center code stuff?
>> Kyle Simpson: Yeah, so you have to start thinking in terms of delegation.
[00:01:47] Delegation is not a general hammer that you'd use everywhere. I only use it 5% of the time at best. But when I do want to take advantage of the prototype mechanism, I think delegation's a cleaner pattern than class is for it. Without belaboring that stuff, I do encourage you as your homework to take a look at exercise 4, try your hand at it.