 So, let's talk a little bit about object oriented programming because when I started my undergrad in computer science it was for a while then it was very difficult to understand even though it's fairly easy and probably I guess it was because nobody spent too much time trying to explain in very detail and very simple terms what is object oriented programming. But before we go into this type of programming we should start with the simplest type of programming which is called procedural programming. It is very simple and straightforward it's something that everyone is starting that's the starting point for everyone who gets into the coding world because it's a very easy top-down approach you start from the top you write line by line your code and every line that you execute you go to the next one and to the next one it's very easy to understand and the basic building blocks for something like that are the decision condition structures the if then else that you might have seen in other languages if a condition is met then execute what the first step else do something else you have the loops where if a condition is met that means that certain lines of our code are going to be repeated as long as this condition is met and finally some the last languages that were following the produce the procedural programming introduced some functions and it was in between step between procedural programming and object oriented programming where you had some specific functions which would do specific things that you could do and you could reuse them every time and you could it would just call the function instead of let's say writing again and again all that the block of code that you needed to execute a specific function if you need anything you can speak up or say something I have that's out in front of me so if you want me to stop to explain anything just let me know so very quickly a procedural programming a very simple example as I said you start from the top you're going down you have some variables that you initialize and then let's say you have an if condition if this condition is met then do something or bypass the whole the whole block of the if and continue afterwards and then you might encounter a for loop so for a specific number of loops do whatever is included in the for loop sometimes and then after you done you can continue calling a second function for whatever reason as you can imagine as we go in and write code line by line if we want to have a very complex project the program is going to get too big and it's going to be very difficult even to understand if you move away for a couple of months let's say from that project and then coming back trying to understand exactly what happened so as I said large projects tend to become very difficult to maintain update change whatever you want so a very quick example I'm pretty sure you have seen this picture of the code that was used to get us to the moon this was for other reasons written in assembly so level programming language and it was a procedural programming and in order to update let's say this code if you or if you figured out that there was a mistake somewhere in the code you can understand and you can imagine how difficult it would be to go back and change something so as I said it's difficult to maintain adding new data new function it's not always the easiest thing to do so and even though it's very easy to understand at first because you're going line by line and it's very easy to understand a small program what exactly does it's not based on the real world what is based on the real world on the other hand is object oriented programming and everything is organized around classes and objects and that's where we're gonna spend our time today the the main difference is the approach that we're using to write our programs we start from the bottom up we create our objects our classes and then we move to create more complex let's say classes methods etc we'll see some examples about that so in order to understand what's going on the first thing we're gonna talk about is are the classes the classes are essentially the prototypes of the blueprints on on which we're gonna base the creation of our objects let's bring a real-life example to understand a little bit better what I'm saying so yeah I just wanted to make sure that the blueprint as a blueprint it contains all the information about the properties of an object if that object is to be created according to that class and all the operations that an object belonging to the class should have so a real-life example cars a very abstract definition we all know what a car is and even though you do not have a car let's say you do not have a car right now but you know what a car is so you have the concept of the class and if let's say someone comes and says to you I bought a car so you move from the abstract definition of the object to the actual object to an instance of that car so you will need some kind of information you're gonna ask your friend hey what did you buy what is the make and model of the car what is the year of the car what how many doors it have how big is the engine what how how big is the gas tank the mileage information that you are a you know already comes along with the broad and abstract definition of the class of the car so when we have an object the car that our friend has bought we need all this information in order to be able to initialize this this object so he will tell us it's a Toyota Camry of the year 2016 has four doors 2.5 liter engine and it has a gas tank of size 14.5 gallons so now we have an object we moved into creating an actual thing based on a theoretical blueprint that was the class and that actually gets us to the first interesting concept that comes along with object-oriented programming and that is the concept of encapsulation what it simply means is that every object belongs to itself it hides most of the information inside itself it keeps its state private and if another object wants to interact with the object and its attributes the only way to do that is through specific methods that we have to give access to other objects to interact between them otherwise nothing is exposed to the outer program so all the attributes are protected inside the cell let's say of an object so and yeah and most importantly unless we explicitly try to do something like that no other class or objects from other classes can actually access this car let's say the Toyota Camry in this case so that leads us to talk about methods we have as we said the attributes of an object but there are some methods that could affect the attributes of the model of an object some examples in this case with a car example we might have a method which would be start the engine and then it flips the attribute engine from engine on from false because the car would be stopped to on because well now we turn the engine on or another method would be tank fill so we would get the the tank that would be empty because the brand new car and we would fill it with gasoline and that lead us to the second important characteristic of object-oriented programming and that is abstraction so we have the ability of different objects communicating with each other a lot but the good thing is that only a high level mechanism is exposed to to the other objects or even us the end user meaning that the inner working of what's going on are hidden inside a black box we don't need to know how the engine might we how we manage to turn the engine on we just have to know that this is the method we use to turn on our engine and it's pretty close to how we use today our phones we don't need to know exactly what happens when we're trying to unlock our phone let's say with our face or our finger print only the highest level of that interaction is exposed to us the inner workings are hidden and protected from us yeah that is exactly what I said so the answer now is on we don't need to know why and how it happened we just need to know that we requested it through a specific method and now it's on and we're getting closer to the third and that leads us to the third special important characteristic of the object oriented programming and that is the concept of inheritance so objects tend to set a lot of characteristics but not they're not always entirely the same what that means in our case with the cars all cars are cars but some cars are different than others so we might have pickup trucks sedans hotspots once so there is a pattern class which is more generic more general and contains information that is spread it out through all kinds of cars and then you have the children of the cars some more specific definitions of cars so a pickup truck will have a flatbed at the on the back where you can load things that's not the same as let's say a sedan but both of them have an engine both of them have doors both of them have a gas tank so there are some specific characteristics that belong to the mother the pattern class and then some more specific characteristics that belong only to the child so the child in here it's everything from the pattern class let's say the engine the gas tank the doors the make and model in here specific characteristics but then it has a collection of characteristics that differentiates its child from everything else so a pickup truck is not the same as a mini one and this way through inheritance we don't have to rewrite everything but a child will have to do and all the attributes that the child must have we just have to inherit everything from the pattern class and then initialize our specific properties that have to have would have to be in the for when we initialize a child let's say a pickup truck in this case so the pickup truck is going to inherit as I said the doors the engine and but then you will have extra attributes in this case which could be the existence of the flatbed or what would be the capacity of that bed is everyone okay so far I'm moving too fast should I go back a little bit just let me know please get it and then it's get a drink too okay Brian says we're good awesome yeah I'll have some examples how to implement all that in Python and so we're gonna move from the super generic explanation of the concept into something more specific how to do that in Python and finally the last thing that I want to talk about is the fourth and characteristic of object oriented programming which is very important to us it's that of polymorphism essentially it's the you could say it's the same as in inheritance but this time for the methods meaning that we can use the methods of a pattern class on the child in the same way that we did it on the pattern class so we don't have to rewrite and re-initialize and redefine I'll be the more correct way to say to redefine the methods that appear on the child but on the patterns so let's say the method let's fill the tank of the car with gas we don't have to rewrite that for every child because it's a it's a common method that should appear to every child and that is why we put it on the pattern so it will be inherited to every child and we can use that method in every child so the start engine and the tank fill should be over there for us available for every children that we might have and but specific methods for the children will have to be defined on the children level in this case let's load the bed of a pickup truck with cargo so these are the four main characteristics of object oriented programming that you should try at least to understand the good thing about the way that the coding word right now works is that you will not have to write most possible most possible you won't have to write your own classes you need to understand what is going on so when you go out let's say on stack overflow or github to get a class or and some objects that pretty much do the work that you need to do in your specific program but all you need to do is to be able to understand what's going on alter a couple of things that you might need so you don't have to reinvent the wheel every time you need to do something new so what I'm gonna do now is I'm going to move on over to Python where I have written some program some objects the classes and the objects for the examples that I brought up about the car so let's tell everything so over here creating the class of the car you might see specifically on this one some different syntaxes around there on the internet that's because the syntax to define a class in the newest version of Python is different that the 2.7 version of Python that ArcMap is using so you might see some differences this is the way to actually define an object in Python so over here we say that we have a class car and we're gonna have some objects from that what I've done over here is that I have a class attribute that they should be distributed along every type of car because well that would be my definition of the car it's a commercial use so the moment I put something like that this is predefined for every object that is going to be created for the class it's gonna have the type commercial and then this is the first and most important method that you have to do in every class that you're defining you define the method of initialization where you say when I want to create an object based on that class what does the outside environment the user let's say has to give me in order to have all the information I need to create a car given the example that I used on my presentation will say that we're not gonna need itself obviously the object the make model year the number of doors the size of the engine and the size of the tank in order to be able to initialize this enough an object based on the car class so what we're saying is that you'll take them the make in this case argument that is gonna be given to you and you will get it into the object and store it into the make attribute and the same will happen for everything else keep in mind that Python is very particularly in terms of indentation so everything that belongs in the class is already intended and the definition of the the the inside part of the definition of the method is intended a second time so we move out in this case and we're gonna try to create our first object so we're gonna say that we have the Camry and it's going to be a car and in order to do that I need to give some arguments to the method the initialization method to create the first object so we will have a Toyota Camry 2014 four doors 2.5 liter engine and 14 gallons of tank and let's say we'll try it after we've done that to see if we have correctly created our first object we're gonna print out the characteristics of these objects so let's run this thing and hopefully everything is gonna work yes it does so the results given the print command that I have used over here is that this is this car is a Toyota Camry made in 2014 it has four doors 2.5 liter engine and a gas tank that holds 14 liters or gallons yeah yeah made that mistake is that's what happens when you come from Europe so now we have created our first object any questions about that or do you need me to explain or add anything in the whole process I will also give I will post when I post the recorded version of this video I will also give all the the four scripts that I'm using over here to create the objects so any questions they aren't too many of us here so if you want to speak with your microphone instead of writing one that's up but should work as well I have a question sure why do you have to have self again because this way we take everything that is given through an argument and when we initialize an object through the class we say take that and put it in yourself that happens because every time you go into the class and create a second object so if I go ahead and create Camry 2 with exactly the same arguments Toyota Camry 2014 for 2.5 and 14 this is going to be a brand new object it's gonna I'm gonna have two identical objects with different names in order to differentiate them and in order to achieve that you need the self part so you can say that take this argument when you initialize the first for the the object for the first time and get that argument into yourself self make so you'll see what's going on in a little bit because when I'm gonna use some methods that I'm gonna create for my class in the second example and I'm gonna use in this case if I want to use the method fill up the tank for the Camry I will use Camry dot the name of the method that I'm gonna use so since there is no name when I'm initializing that the the class and I'm creating the blueprint the way to substitute that is by using the word self I think I might have given you an answer okay I think I get it okay you'll get it a little bit better I think in the second example and so right now we only have a an object of the car but I'm gonna go ahead yeah one question sure the format for the init function has the two underlines and I see that a fair mountain Python does that signify anything in particular to have the two underlines before the name of a function I guess this is the constructor in this case for that it's a constructor and I don't have a specific answer for you my intuition would be that if we decide to short all our all our methods this is going to pop up the very first of the very top because that's where you need the constructor and well there should be a reason why there is wipes the people who created Python figured that the constructor with initialization should have the two underscores but my two cents would be that it would be in terms of the shorting it's always gonna pop up at the very first at the top are we good I might have a better answer for you actually it's a good question I will look at it and maybe I'll have something if I find something I will post it on the discussion that's good I haven't seen that with other programming languages it seems like I only see that in Python I only see it with some of the functions that are defined they're just kind of yeah right I haven't seen it elsewhere as well I have some experience experience with Java and are a lot lately but I haven't seen it anywhere else so I'm guessing it's one of the quirks that every language I mean it's bound to have all right thank you so I'm gonna go and move one step forward and get the car the definition of the class of the car and define some methods so in this case I'm changing a little bit the definition of the class of the car so we still have that it's a commercial vehicle and in the initialization I am requesting exactly the same number and of attributes the exactly the same attributes but at the end over here because I want to initialize and create the method to fill up the gas tank I'm saying that the the gas in the tank attribute I'm not expecting that to be given to me by the user I'm just saying it's a brand new car nobody has been able to drive it yet it has zero literate gallons in the tank and that's why I'm going myself I'm initializing this attribute of this object being zero so in still if you can see inside the class in the detention I'm keep I'm keeping the indentation over here I'm defining a brand new method that is called tank fill where again I'm gonna need itself because it's gonna affect the attributes of the of the object and the object that I'm and also I'm gonna need the second argument which would be what is the gas quantity how much gas do you want to put in the in the tank so what this method is doing is it's it says to the it's inside the class the blueprint is that it will take the attribute gas in the tank and it will add to what is already inside the tank the gas quantity that I'm requesting that is the plus equals sign is over there to do it keeps the already existing amount of let's say in this case gas inside the tank and adds that the gas quantity that I'm using so you'll see that in action and I'm also wanting to see how much gas I'm gonna have after I feel the gas tank so I'm getting requesting a return message there are gas in the tank gallons in the tank of the car so again what I'm doing in order to use that I'm create I'm gonna create the exactly the same object as before and then I'm gonna go and say since my name of my object is Camry I'm gonna use the tank fill method on the Camry object that I have created so and then in order to see how the plus equal sign actually works I'm gonna fill it up a second time the first time with two gallons and then with ten more so let's see what's going on over here and we're getting these results at first it started the object with zero over here because I said during the initialization of the object that the gas in the tank should be zero and then I'm adding two and then I'm adding ten more so that's why we're getting two messages at first we're getting two gallons and then two plus ten twelve gallons inside the Toyota Camry are we good with the methods again what I'm saying is over here is that probably you will not have to initialize and create your own objects and classes at least nothing too convoluted nothing too crazy but you need to have a general understanding when you're finding code online to understand what's going on and what do you need to edit and alter in order to be able to reuse it in your own programs so any questions about the methods so is it true that a method since it's used by a class it can it seems like it's returning like gas in a tank and make and model so it can use the I guess the parameters of the class yes so essentially that goes back to the for the encapsulation that I was saying during the presentation where the attributes by themselves are protected so if it was a procedural programming and let's say x was the gas tank I would start with x equals two and then x equals ten I will have I would be able to have direct access to the attribute this is not happening anymore I have I'm only able to alter the the attributes of a class through a method and there is only a specific let's say number and types of other objects or users that are available that have the privilege and the rights to use the method and alter the attributes of a class so everything in there is protected and obviously over here it's a very simplistic method doesn't do anything in particular there might be some methods that are hundreds of lines but I do not have to know exactly what's going on inside the method I just need to know that this method does that for me and it's changing the attributes thank you okay awesome so what I'm going to do after this one is open up this over here and I'm going to create a child class based on the car so again most of it is exactly the same I have the car class the commercial again the same arguments the gas in the tank the the method that I have created that I created for the car and then I'm going to create the side class of the pickup truck what I'm saying over here is that I'm defining a class it has the name pickup truck and I'm saying I'm designating over here that this actually is an extension of a car object so everything that is declared of and defined over here should be available to me in the child part of this class which is a child of the class car so in order to initialize it again I'm going to use the same arguments that are required for a car up until the tank and then because it has some extra elements as I said before in this case just the bed capacity for the cargo that pickup truck can actually use for you I'm inserting an extra argument at the end of the constructor so I'm saying that since this is a car what you need to do is use the initializer this method from the car class and do exactly what the car class is supposed to do over here and then additionally for this class for this child class get the bed capacity from the argument that he was given to you and then since it's brand new and nobody has put anything on the bed just say that the bed fill the the capacity for cargo is set at zero or the capacity the actual cargo right now is set at zero and then since this is a child class the the tank fill should be available for us to use in the child class but we have the specific method over here which would be load the bed where we would get some cargo and throw it on the bed of the pickup truck so we will have something to carry around and then it will return for us a message so what i'm doing over here i'm creating our first pickup truck this is uh i'm going to call it a ram i'm using the pickup truck which is the name of the class and i'm saying this should be a dodge ram in 2019 four doors five uh guess windows 19 gallons of capacity in the tank and 350 whatever capacity in the in the bed in the back and then i'm gonna fill it with um some gas because you need to be able to use the methods that are coming from the parent class and then i'm gonna use and load the bed uh of the of the ram with something that i want to move around so if i was to run this thing over here this is our results at first we get three gallons of gas inside our tank and then added three thirteen so the total should be as you can see over here sixteen so the method even though it was declared at the parent class it is available and works exactly the same in the child object and then we say that the bed right now holds 43 kilos of cargo on the bed and a very simplistic again example of how to define a parent class and then extend it into having a child class any questions yes we're good if you want to ask anything just let me know and then what i've done over here is i changed things a little bit uh so even though you'll in terms of the the classes in the material for the classes you'll see the if structure on the second week if you have any experience and exposure to coding you will know that they're available to you some if structures and i'm just using over here one to protect let's say our object for from overloading it with cargo so what i'm doing is i have exactly the same here the exactly the same class definition of the car almost exactly the same thing for the pickup truck the same initializer but what i'm doing is i'm changing a little bit the previous definition of load the bed and what i'm saying is that if whatever is available already on the bed field plus the cargo that i'm getting that the user wants me to throw in the on the bed is less than this could have been less or equal to tell you the truth that the bed capacity that means that i can throw the cargo safely on the bed on the back of my pickup truck and i would say now we have this many of kilos of cargo on the bed of my truck else which would mean the opposite that the bed field plus the tendon cargo to be loaded would be larger than the capacity i would get another message which would be too much cargo cannot load the total load remains at that so the cargo wouldn't be added to the existing load on the pickup truck so what i'm going to do is i'm going to keep the same things with the with the time field and then i'm going to load up the the bed with something that can be loaded only 43 kilos and then 200 which would be less altogether than 350 and then i'm just going to try and overdo things and see what will happen so again we're getting these messages the first two are exactly the same because we didn't change anything in the method of the tank fill and then i have the first load of 33 kilos plus 200 it gives me 243 kilos and then i try to get over a tone and i'm getting the message too much cargo cannot load and the total load remains at 243 just a quick example of how many things can happen inside the method that we don't actually have to know about so again the user you as a user only need to know that you'll need to know the name of the object the method and you don't really have to know what is going on in the inside in the black box of a method so in this case we added the protection to not break the car by throwing too much cargo on the back of the pickup truck and any questions about that pretty much that's all the the full extent of what i had for you today especially for the people who have no zero to little experience working with object oriented programming languages so any questions you might have are welcome and if you happen to think anything just feel free to throw it on the discussion board