1 00:00:00,400 --> 00:00:01,400 Hello, everyone. 2 00:00:01,640 --> 00:00:06,720 This is the fifth sequence on inheritance and lookup. 3 00:00:07,320 --> 00:00:10,320 We'll be covering messaging 4 00:00:10,600 --> 00:00:13,120 and lookup algorithms for metaclasses. 5 00:00:13,440 --> 00:00:14,560 In Pharo, 6 00:00:14,880 --> 00:00:16,400 everything is an object, 7 00:00:16,520 --> 00:00:19,400 and objects can receive messages. 8 00:00:19,800 --> 00:00:23,200 So classes are objects, too. 9 00:00:23,760 --> 00:00:26,120 And since objects can receive messages, 10 00:00:26,320 --> 00:00:28,040 classes can receive messages. 11 00:00:28,480 --> 00:00:33,480 The messaging mechanism is exactly the same, 12 00:00:33,800 --> 00:00:37,040 whether the receiver is a class or other object. 13 00:00:38,840 --> 00:00:42,360 There is only one way to look up a method. 14 00:00:42,720 --> 00:00:46,280 This is the lookup algorithm we've seen several times 15 00:00:46,440 --> 00:00:48,320 in earlier sessions. 16 00:00:49,200 --> 00:00:51,560 Now let's look at the example 17 00:00:51,760 --> 00:00:54,200 of messaging a class. 18 00:00:56,240 --> 00:00:58,160 Understand the basic principle: 19 00:00:58,640 --> 00:01:00,880 Since classes are objects, 20 00:01:02,040 --> 00:01:04,400 and each object is linked to a class, 21 00:01:04,560 --> 00:01:07,000 that is, an instance of a class, 22 00:01:07,240 --> 00:01:10,520 aNode is an instance of Node class. 23 00:01:10,920 --> 00:01:15,040 Since Node class is an object, 24 00:01:16,160 --> 00:01:19,120 Node class is an instance of another class. 25 00:01:19,680 --> 00:01:22,560 It is called Node class. 26 00:01:22,880 --> 00:01:25,200 So, aNode is an instance of Node class, 27 00:01:25,760 --> 00:01:30,120 and Node class is an object that is an instance of Node class class. 28 00:01:30,840 --> 00:01:33,280 If that's the way it is, you may wonder 29 00:01:34,120 --> 00:01:39,280 Node class is a class; a class is an object, an instance of a class. 30 00:01:39,600 --> 00:01:43,400 which class Node class is an instance of. 31 00:01:43,840 --> 00:01:47,800 You will see that in the next sequence, on metaclasses. 32 00:01:48,240 --> 00:01:50,560 Here are a few examples. 33 00:01:50,960 --> 00:01:56,880 Here, the object, aWorkstation, is an instance of Workstation class. 34 00:01:57,040 --> 00:02:00,480 Workstation is a subclass of Node, a subclass of Object. 35 00:02:00,640 --> 00:02:03,320 Here, you must pay attention to the arrows. 36 00:02:04,200 --> 00:02:06,360 The arrow with a blank tip 37 00:02:07,000 --> 00:02:09,160 indicates a subclass relationship. 38 00:02:09,400 --> 00:02:12,280 Node is a subclass of Object. 39 00:02:12,640 --> 00:02:14,760 Workstation is a subclass of Node. 40 00:02:15,040 --> 00:02:17,600 The arrow with a black point, 41 00:02:17,920 --> 00:02:21,800 is sometimes represented as a simple two-line arrow, too. 42 00:02:22,160 --> 00:02:23,960 It indicates instanciation. 43 00:02:25,320 --> 00:02:27,880 aWorkstation is an instance of Workstation. 44 00:02:28,160 --> 00:02:30,600 Workstation is an instance of Workstation class. 45 00:02:30,920 --> 00:02:34,280 Likewise, Object is an instance of Object class. 46 00:02:34,680 --> 00:02:36,160 If I message 47 00:02:36,360 --> 00:02:37,880 the object aWorkstation, 48 00:02:39,680 --> 00:02:42,880 the lookup algorithm searches the aWorkstation class. 49 00:02:43,400 --> 00:02:45,640 Then it goes up through superclasses 50 00:02:45,800 --> 00:02:48,240 until it finds a matching method. 51 00:02:48,720 --> 00:02:51,920 The mechanism is exactly the same 52 00:02:52,440 --> 00:02:56,320 when I message the Workstation class. 53 00:02:56,720 --> 00:03:00,440 For example, if I send the message "new" 54 00:03:00,960 --> 00:03:04,080 to Workstation, the lookup algorithm 55 00:03:04,280 --> 00:03:08,280 searches Workstation class for a method called "new." 56 00:03:08,920 --> 00:03:11,160 If it finds it here, it executes it. 57 00:03:11,400 --> 00:03:14,960 If it does not find a match, it moves up to the superclass, 58 00:03:15,120 --> 00:03:17,880 and then up to the next superclass. 59 00:03:19,000 --> 00:03:21,760 And so on. This hierarchy continues. 60 00:03:22,960 --> 00:03:26,880 I'll leave you with this slide summing up messaging 61 00:03:27,040 --> 00:03:30,560 to standard objects and classes as standard objects. 62 00:03:31,800 --> 00:03:33,120 Here's what to remember: 63 00:03:33,480 --> 00:03:36,360 A class is an object like any other. 64 00:03:37,040 --> 00:03:40,680 Messages can be sent to objects, and therefore to classes. 65 00:03:41,480 --> 00:03:45,640 The lookup mechanism is exactly the same in both cases. 66 00:03:47,400 --> 00:03:51,280 It starts searching in the class of the receiver, 67 00:03:51,680 --> 00:03:55,400 and then searches each superclass in the inheritance chain 68 00:03:55,760 --> 00:03:58,120 until it finds a matching method. 69 00:03:58,600 --> 00:04:02,880 You'll learn more about metaclasses in "Understanding Metaclasses."