1 00:00:00,690 --> 00:00:01,690 ‫Welcome back. 2 00:00:01,710 --> 00:00:08,640 ‫And this video I would like to talk about members and therefore, I just create a new class here and 3 00:00:08,640 --> 00:00:10,290 ‫I'm going to call it members. 4 00:00:11,670 --> 00:00:16,590 ‫Now, in this member's class, I want to go ahead and create all the different types of members that 5 00:00:16,590 --> 00:00:20,550 ‫are relevant when working with object oriented programming. 6 00:00:20,550 --> 00:00:24,660 ‫So we have private fields, for example. 7 00:00:24,660 --> 00:00:37,470 ‫So let's call a member private field here, and that would be something like private string 8 00:00:39,780 --> 00:00:46,170 ‫member, name ten private string job title. 9 00:00:46,470 --> 00:00:49,260 ‫So these are just examples of members. 10 00:00:49,260 --> 00:00:52,470 ‫So they can be private fields, they can also be public fields. 11 00:00:52,470 --> 00:00:57,570 ‫So remember they called member fields, so. 12 00:00:58,300 --> 00:01:04,120 ‫This would be public field and that's public int h. 13 00:01:04,210 --> 00:01:08,230 ‫So just as an example, right, then a member could have a salary. 14 00:01:08,830 --> 00:01:09,790 ‫All those kind of things. 15 00:01:09,790 --> 00:01:17,320 ‫So all of these variables, these fields, these global variables, they are members of this class members. 16 00:01:17,530 --> 00:01:21,340 ‫So then there are properties which are also members. 17 00:01:21,340 --> 00:01:28,570 ‫So let's say I want to have a property, I'm just going to prop here and then double tap and I get this 18 00:01:28,570 --> 00:01:34,510 ‫property and it's going to be the string job title. 19 00:01:34,600 --> 00:01:36,010 ‫Job title. 20 00:01:36,430 --> 00:01:41,710 ‫So we have that here, which was a private field and now I create a property with the same name, but 21 00:01:41,710 --> 00:01:42,880 ‫with a capital J. 22 00:01:43,090 --> 00:01:48,370 ‫And in here we have a getter and setter, and they are also created, automatically created. 23 00:01:48,370 --> 00:01:52,600 ‫But we can also go ahead and create the manually, as you have seen in the last video. 24 00:01:52,600 --> 00:01:54,670 ‫So let's just do that real quick. 25 00:01:54,670 --> 00:02:07,510 ‫So instead of get and set with the standard here, I want to get I want to return the job title and 26 00:02:07,510 --> 00:02:14,830 ‫instead of a standard setter, I want to use something like job title should be set. 27 00:02:14,830 --> 00:02:18,130 ‫So job title is going to be the value that is given to us. 28 00:02:18,640 --> 00:02:18,970 ‫All right. 29 00:02:18,970 --> 00:02:25,300 ‫So that's our get set and let's clean it up so that it looks a bit better. 30 00:02:25,300 --> 00:02:35,020 ‫So this is a member property which exposes job title safely and generally. 31 00:02:35,020 --> 00:02:48,730 ‫So, you know, just remember properties start with a capital letter, then we have a member which is 32 00:02:48,730 --> 00:02:49,330 ‫a method. 33 00:02:49,750 --> 00:03:00,340 ‫So let's create a public member method which can be called from other classes. 34 00:03:02,170 --> 00:03:08,380 ‫As you know, with public methods they can be called from other classes and methods within a class are 35 00:03:08,380 --> 00:03:10,030 ‫called her members. 36 00:03:10,030 --> 00:03:12,490 ‫So the members class. 37 00:03:13,890 --> 00:03:18,570 ‫In our case, this is a class called members, but whatever the name of the class would be, so let's 38 00:03:18,570 --> 00:03:20,310 ‫say it's student. 39 00:03:20,310 --> 00:03:24,690 ‫So you have a class with all of your students, all the information about students and the skills of 40 00:03:24,690 --> 00:03:25,980 ‫students and so forth. 41 00:03:26,190 --> 00:03:29,400 ‫Then a method in there would also be a member. 42 00:03:30,150 --> 00:03:32,370 ‫So let's just create an example. 43 00:03:32,730 --> 00:03:42,510 ‫Public void intro juice thing and bool is friend. 44 00:03:42,780 --> 00:03:49,680 ‫And what I want to do in here is simply introduce someone and if it's a friend then I want to introduce 45 00:03:49,680 --> 00:03:53,520 ‫myself in a, let's say, more private way or something like that. 46 00:03:53,550 --> 00:03:54,150 ‫All right. 47 00:03:54,150 --> 00:03:59,670 ‫So let's say we have just a different another one. 48 00:03:59,670 --> 00:04:03,600 ‫I'm going to add another field here, which is going to be a celery. 49 00:04:04,080 --> 00:04:07,560 ‫So private and celery. 50 00:04:08,970 --> 00:04:14,280 ‫And now if it's a friend, I want to tell them about my celery as well because I wouldn't share that 51 00:04:14,280 --> 00:04:15,270 ‫with somebody else. 52 00:04:15,270 --> 00:04:20,250 ‫But instead of using a public method, I'm going to use a private method for that. 53 00:04:20,250 --> 00:04:23,390 ‫So I don't want to do that within the introducing itself. 54 00:04:23,400 --> 00:04:31,740 ‫I want to create a different method for that and it's going to be private void sharing private info 55 00:04:31,890 --> 00:04:39,240 ‫and it's going to write something like, hi my well actually just call my celery. 56 00:04:39,240 --> 00:04:41,940 ‫My celery is the celery. 57 00:04:43,500 --> 00:04:47,370 ‫Now, of course, we need to know the celery or there has to be a celery value. 58 00:04:47,370 --> 00:04:50,610 ‫So let's just set that as a standard value. 59 00:04:50,610 --> 00:04:58,560 ‫So minimum 20,000, that's how much our members minimum celery is going to be. 60 00:04:58,560 --> 00:05:04,050 ‫So that's going to be the shared private info and I use this bool is friend whatever introducing is 61 00:05:04,050 --> 00:05:16,680 ‫called to call sharing private info or not so if is friend then I want to call share private info. 62 00:05:17,820 --> 00:05:20,640 ‫Otherwise I'm just going to write something like. 63 00:05:20,640 --> 00:05:41,100 ‫LS CW Hi, my name is Curly Brackets zero and my job title is Curly Brackets one and then I'm Carter 64 00:05:41,100 --> 00:05:44,850 ‫Brackets, two years old. 65 00:05:45,960 --> 00:05:48,420 ‫And now we of course need all of this information. 66 00:05:48,420 --> 00:05:52,710 ‫So the one was the member name. 67 00:05:54,540 --> 00:05:58,740 ‫Then we had the job title and we had the H. 68 00:05:59,280 --> 00:06:05,970 ‫So all of those are given if somebody is not a friend because our friend would usually know these kind 69 00:06:05,970 --> 00:06:09,300 ‫of things, our job title member, whatever. 70 00:06:09,300 --> 00:06:13,950 ‫But if we want to introduce some new information to our friend, it's going to be something like my 71 00:06:13,950 --> 00:06:14,550 ‫salary. 72 00:06:14,550 --> 00:06:19,350 ‫Well, it's just an idea that I came up with that's private that I wouldn't tell somebody on the street 73 00:06:19,350 --> 00:06:19,920 ‫usually. 74 00:06:19,920 --> 00:06:23,580 ‫And then we even have a different member, which is a constructor. 75 00:06:23,580 --> 00:06:25,620 ‫So a constructor is also a member. 76 00:06:25,620 --> 00:06:32,790 ‫So if I create a member's constructor here, this is going to be a member. 77 00:06:33,630 --> 00:06:42,060 ‫So the constructor is a member console right line and it's going to be something like object created, 78 00:06:43,140 --> 00:06:43,770 ‫very simple. 79 00:06:43,770 --> 00:06:48,240 ‫So whenever a member is created, we simply have this object created. 80 00:06:49,140 --> 00:06:55,710 ‫And what we also should do in here is because we don't have any values for our member name, job title 81 00:06:55,710 --> 00:06:56,520 ‫and salary. 82 00:06:56,520 --> 00:07:02,880 ‫Actually, we can get rid of that salary here and we're going to initialize it just in members. 83 00:07:02,880 --> 00:07:10,830 ‫So we're going to say H is going to be, let's say 30 then member name is going to be Lucy. 84 00:07:11,730 --> 00:07:22,620 ‫Then we have the salary and Lucy earns a great amount of $60,000 or euros, whatever you like. 85 00:07:22,620 --> 00:07:25,110 ‫And then we have what else do we have? 86 00:07:25,110 --> 00:07:27,480 ‫So we had salary member name, job title. 87 00:07:27,480 --> 00:07:29,460 ‫So what's her job title? 88 00:07:30,540 --> 00:07:33,300 ‫Let's say she's a developer 89 00:07:35,850 --> 00:07:42,300 ‫and we're not going to go into detail what type of developer she is, but that's our members constructor. 90 00:07:42,300 --> 00:07:46,260 ‫And the constructor itself is a member of this class. 91 00:07:47,250 --> 00:07:54,960 ‫And finally we have something called Final or Destructor, which is also a member, and the destructor 92 00:07:54,960 --> 00:08:02,430 ‫is created with this curly sign here, and then the name of the class, which is a members or which 93 00:08:02,430 --> 00:08:03,690 ‫is members simply. 94 00:08:03,690 --> 00:08:08,700 ‫And this final user or destructor cannot be defined in structs. 95 00:08:08,700 --> 00:08:13,200 ‫It's only possible to do that within classes and. 96 00:08:13,290 --> 00:08:15,870 ‫A class can only have one final loser. 97 00:08:15,870 --> 00:08:21,480 ‫So we have seen that we can create multiple constructors, but we can only create one destructor per 98 00:08:21,480 --> 00:08:28,410 ‫class and that final sizer cannot be inherited or overloaded and it cannot be called. 99 00:08:28,410 --> 00:08:32,190 ‫So it's only there for this specific class. 100 00:08:32,190 --> 00:08:39,480 ‫So whenever the object runs out of scope, so our members object runs out of scope, this file analyzer 101 00:08:39,480 --> 00:08:42,720 ‫will be called and let's just create one. 102 00:08:42,960 --> 00:08:46,500 ‫By the way, it's there for clean up statements. 103 00:08:47,160 --> 00:08:49,350 ‫So only cleaning up is useful here. 104 00:08:49,350 --> 00:09:00,360 ‫And let's just write something onto the console, something like deconstruction of member object. 105 00:09:01,290 --> 00:09:08,220 ‫So whenever the object is closed or deleted or runs out of scope, that's when this method here or this 106 00:09:08,220 --> 00:09:13,980 ‫final loser is executed and empty final losers. 107 00:09:13,980 --> 00:09:17,250 ‫So if this should be empty, you should not use it. 108 00:09:17,250 --> 00:09:20,550 ‫So only if you have something useful to do in here. 109 00:09:20,550 --> 00:09:25,710 ‫You should ever use a file analyzer because otherwise it just uses up performance. 110 00:09:25,710 --> 00:09:31,320 ‫So you just have needless loss of performance because when the class contains the file analyzer, an 111 00:09:31,320 --> 00:09:37,560 ‫entry is created in the finalizing queue and when if analyzer is then called, the garbage collector 112 00:09:37,560 --> 00:09:39,510 ‫is invoked to process that queue. 113 00:09:39,510 --> 00:09:44,880 ‫And well, that's why you shouldn't create an empty finalize because it's just going to add something 114 00:09:44,880 --> 00:09:50,160 ‫into the queue which is not doing anything and that still reduces performance. 115 00:09:50,610 --> 00:09:50,940 ‫All right. 116 00:09:50,940 --> 00:09:55,290 ‫So that's generally the file analyzer or the destructor. 117 00:09:55,680 --> 00:10:03,880 ‫And in order to test that, it's quite difficult because we if we run out of scope, which in our case 118 00:10:03,880 --> 00:10:10,830 ‫is if we run out of the main method, then there's simply not much that we still see because our program 119 00:10:10,830 --> 00:10:12,180 ‫simply closes, right? 120 00:10:12,180 --> 00:10:16,650 ‫So let's just create a member's object and I'm going to call that number one. 121 00:10:16,650 --> 00:10:18,600 ‫It's going to be new members. 122 00:10:19,050 --> 00:10:24,630 ‫And this new members or number one is simply going to be our Lucy. 123 00:10:24,690 --> 00:10:31,440 ‫So we don't have a constructor where we set the age and the member name and the salary, all those kind 124 00:10:31,440 --> 00:10:31,830 ‫of things. 125 00:10:31,830 --> 00:10:37,470 ‫Because we keep it simple in this video because it's mainly about the general idea of members and to 126 00:10:37,470 --> 00:10:39,480 ‫finalize or the structure. 127 00:10:39,660 --> 00:10:47,460 ‫So now let's call number one and let's let her into use or let's call the introducing method. 128 00:10:47,460 --> 00:10:54,720 ‫So now she's going to introduce herself and in here we need to give a boolean. 129 00:10:54,720 --> 00:10:59,100 ‫So I'm just going to say, okay, I am a friend, so please tell me your salary. 130 00:10:59,580 --> 00:11:03,810 ‫So because that's what this introducing method does. 131 00:11:03,810 --> 00:11:11,310 ‫And by the way, it's going to call this sharing private info method within the introducing method. 132 00:11:11,310 --> 00:11:19,890 ‫So that's the only way around of getting something of a private method outside of that class by calling 133 00:11:19,890 --> 00:11:22,530 ‫the private method within a public method. 134 00:11:22,530 --> 00:11:25,890 ‫So this sharing private info is a private method. 135 00:11:25,890 --> 00:11:31,560 ‫So the access modifier is private, but this public method here can be called from outside, which means 136 00:11:31,770 --> 00:11:34,680 ‫it can be called within our program class, for example. 137 00:11:34,680 --> 00:11:42,180 ‫And then here, if I try to access that sharing private info, it's going to say members share and private 138 00:11:42,180 --> 00:11:45,780 ‫info is inaccessible to due to its protection level. 139 00:11:45,780 --> 00:11:47,880 ‫So I just just cannot access it. 140 00:11:48,090 --> 00:11:53,580 ‫Now in order to show you this deconstruction of member object. 141 00:11:53,880 --> 00:11:54,660 ‫Done. 142 00:11:55,530 --> 00:11:55,860 ‫Yeah. 143 00:11:55,860 --> 00:11:59,370 ‫This call here, we need to get out of scope. 144 00:11:59,370 --> 00:12:03,990 ‫Which means as soon as we close the static void main. 145 00:12:03,990 --> 00:12:10,230 ‫So as soon as we get, let's say, to line 18, in my case, that's when the final user is called. 146 00:12:10,230 --> 00:12:14,010 ‫So that's when member one is going to be destroyed. 147 00:12:14,880 --> 00:12:20,520 ‫If we run that, we will see it for a very, very short second. 148 00:12:20,520 --> 00:12:23,040 ‫So let me create it. 149 00:12:23,910 --> 00:12:27,450 ‫Actually, it's just going to close directly. 150 00:12:27,630 --> 00:12:32,550 ‫So let's write console.log, read key in here. 151 00:12:33,060 --> 00:12:38,040 ‫So you see something so that we are my salary is so she. 152 00:12:38,040 --> 00:12:40,470 ‫Well, the object is created. 153 00:12:40,470 --> 00:12:44,250 ‫She tells us the salary because we are a friend, as we said here. 154 00:12:44,250 --> 00:12:44,760 ‫True. 155 00:12:44,760 --> 00:12:50,010 ‫And now if I press enter for a split second, you can see that there is some text there. 156 00:12:50,040 --> 00:12:52,050 ‫Actually you don't see it. 157 00:12:52,200 --> 00:13:00,360 ‫But in the end, after I press the console key, I run into this line here and then the code is executed. 158 00:13:00,810 --> 00:13:08,280 ‫So in order to see that we will need to use debug here and we will need to import debug so show potential 159 00:13:08,280 --> 00:13:09,150 ‫fixes. 160 00:13:09,180 --> 00:13:12,810 ‫All enter use system diagnosis. 161 00:13:13,110 --> 00:13:17,130 ‫Are agnostics just going to do that debug thought? 162 00:13:18,270 --> 00:13:21,330 ‫And here now I can call something bright. 163 00:13:21,330 --> 00:13:26,340 ‫And I just want to write onto this output here and I'm just going to call just that. 164 00:13:26,340 --> 00:13:34,260 ‫So deconstruction or destruction because it's destruction of members object. 165 00:13:34,260 --> 00:13:35,400 ‫What is happening. 166 00:13:35,640 --> 00:13:37,560 ‫So now let's run it again. 167 00:13:38,450 --> 00:13:39,740 ‫Actually without the key. 168 00:13:39,740 --> 00:13:41,690 ‫We don't need that anymore because we're fine. 169 00:13:41,690 --> 00:13:45,590 ‫If the program simply closes afterwards, we're just going to run that. 170 00:13:45,590 --> 00:13:51,530 ‫And we see here the structure or destruction of members object. 171 00:13:52,400 --> 00:13:56,990 ‫And actually if we get back, we just had their console key. 172 00:13:57,590 --> 00:14:01,190 ‫So you can see that it's not executed. 173 00:14:01,190 --> 00:14:08,570 ‫So we don't see this information, but only after we press enter that we saw it for a second. 174 00:14:08,570 --> 00:14:12,890 ‫Deconstruction of a member object or a member of this object was shown. 175 00:14:12,890 --> 00:14:19,820 ‫So that's how you see how structures or file analyzers generally work and what they do. 176 00:14:20,150 --> 00:14:20,600 ‫Great. 177 00:14:20,600 --> 00:14:23,240 ‫So now you have seen the different types of members. 178 00:14:23,240 --> 00:14:28,340 ‫There is a little more to know about members, but just check out the documentation. 179 00:14:28,400 --> 00:14:32,420 ‫Then you will see a little more detail what members are and what they do. 180 00:14:32,420 --> 00:14:38,450 ‫But for the most part, what we have seen here is going to cover pretty much most of the things that 181 00:14:38,450 --> 00:14:40,790 ‫we're going to handle on use in the future. 182 00:14:40,790 --> 00:14:41,150 ‫Great. 183 00:14:41,150 --> 00:14:43,100 ‫So see you in the next video.