We will be undergoing scheduled maintenance on May 20th, 2013 at 02:00 GMT.
Welcome to Part Two of Object Orientated Development. And in this video, I want to show you just a real brief animation that really should kind of make it click about the relationship between classes and objects and how you instantiate those objects. What we're going to do, with say our fictional veterinary program here, is notice we're going to first code up a class. Now notice we do Public Class Animal, you'll see this a little bit later on in the course. But we're going to set up some Strings here for some variables. These would actually be Properties, we'd do them a lot differently than this, but to make it simple here. Notice for every Animal Object that we create, we want to store a name, the type of animal, whether it's canine, feline, whatever the other ones are, I don't know. The weight of the animal and then some, something about the bill here. I don't know what that would be but anyway. And then we're going to have office visit as a method for this particular animal, and this also might even better put in an Exam Class or whatever. But this is just a little function if you will that runs and this becomes a method on the object. So it just takes the amount of, the difference between the time the patient came in to the time they leave and we subtract that out and set it equal to bill. Then we return bill and then we'll multiply that by whatever hourly rate or whatever, you know, metric that the doctor wants to use. Okay. But anyway, that's a class. Okay. So we code that up and we have it out there. And then we can execute this command. We can put this command in our code and notice animal is a Type and it's talking about this class which is a Type or a class. And then we're going to create an Instantiated Object off, of this class or this Type called Animal. We're going to call it A and we're going to set A equal to a new instance of this Animal Class. Now when we execute this command in our code, what happens is, an object called A, notice right here, A, gets built on the class Animal now exists in memory. And so we can set the String Name, the type, the weight, the integer of bill and we can set those and those will apply only to object A. Now if you're hard core C Sharper, don't worry about how I've got these set up. Okay. But these would be our Properties. So object A has a distinct name, type and weight and this is in memory. Then we can do another command, Animal B equals new animal. So we're creating a variable or an object called B based on the animal type and then we're creating that in memory by passing the new keyword and telling it a new instance of the Animal Class. And that creates another object that starts out identical to where A started out. And this one is called B and B can have it's own unique name, type, weight, bill and it can execute this method. So we create this object, say for you know, a dog named Spot that comes in. This is for a cat named Fluffy that comes in. And Object A for Spot can write this stuff back and forth to a database, store information, change things. The method can just record in the database what we did to Spot. What treatment Spot received, what should be billed and all that sort of thing. Then down here, Fluffy the kitten has the same things working. So basically we have just simply built 2 objects in memory that represent this real world Instantiation of an animal. Okay. Spot the dog, Fluffy the cat. If you can get your head around that, if you can get that visual in your head, that will go a long way to understanding this whole idea of Object Orientated Development. We're going to create objects in memory, work with those. And then when we're done, we'll simply destroy that object, take it out of memory and we've already written our information to the database or whatever we want to do with it. And then the object goes away and we can continue. It's a very efficient use of memory and if we ever want to change how all of our objects work. We simply go back to our class, make a change in the code. The next time somebody creates a New Object, it has all that functionality and any future objects that get created. So that's a real quick visual overview of Object Orientated Development.
| Course: | Microsoft C# 2010 |
| Author: | Mark Long |
| SKU: | 34306 |
| ISBN: | 978-1-61866-037-4 |
| Release Date: | 2012-03-19 |
| Duration: | 8.5 hrs / 105 lessons |
| Work Files: |
Yes |
| Captions: | No |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |