Home
Username:
Password:
Introduction to Microsoft Visual Studio 2008 Tutorials

Object Oriented Programming / Visual Coding with Class Designer




Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.


Learn More

Subtitles of the Movie

Now let's take a look at the Class Designer. Now I've done kind of a cheap setup here in the Course. We've done a number of videos, we did one called what is Object Oriented Programming, introduced you to the idea. There's the video called Classes and Objects, it talks about the relationship between Classes and Objects. Then we talked about how to Create a Class, and you actually saw how to do it in code. Then we Instantiated Objects off that Class so you would understand how all this works. Now, once you're OK with that I want to show you this Class Designer and this is huge, this is very powerful. Let's open Visual Studio and let's create a New Project, OK? Let's create a Project and let's just call it VTCClassExample. Alright? And I will click OK, and I've got a blank Form and if you look at my Solution Explorer, OK, we just have this, we have our Form out here. Now if you remember in our other examples we put Buttons out here and then we went and built Classes in our code and we just dropped the Class as Ð I double-clicked there Ð we just put our Classes down in this area, right, all down in here, and they were part of this Module. Well, what we're going to do now is, actually the better way to do it is, we're going to include our Classes out here as separate items totally. And there are a lot of different ways to do this, we won't get into it now. This is not a programming class, but I want to show you what you can do. Now, there are two ways to do this Class Designer and I want to show you both of them because you will see this. If I right-click on the Project you will see View Class Diagram. If I do that it will bring up the Class Designer but it's going to show me every Class in my Project and that will confuse you at this point, most likely. If that doesn't confuse you, if a bunch of lights just started flashing for you, then go for it, OK. But I'm going to cancel this and not save it, and I'm going to come back over here and delete that Class Diagram that got put in there, OK? I'll show you the better way to do this. If I right-click on my Project and say Add New Item, make sure you do this, I right-click on my Project name, choose that, say New Item, you will notice there is a Class Diagram right here. OK? Let's call this VetClasses, because we're going to create that patient and animal Class a different way this time. I'll click Add and you'll notice it brings up the environment here. And notice I can now just, I want to create a Class so I grab Class over here out of the Toolbox, drag it and drop it. It says: What's the name of your Class? And I'll say, well, Patient. It's Public. I can choose various things Ð don't worry about that now Ð this is going to be the actual name of my file that will show up here in my Solution Explorer: I say OK. Notice there's a picture of my Class. I right-click the Class and say Add. You remember the Properties and Methods? Well, I can add a Property here, and this will actually do it the right way. I didn't want to confuse you, but there's a Property called name for the patient, put name in and press Enter. Notice it put the Type in as an Integer and I can just go over here and change it to String and hit Enter and it changed it. Right-click in the blue area, add another Property called phone. I'll leave that one as Integer, that's fine. Right-click. Remember the Methods? Let's add a Method. What do patients do? They pay their bill, hopefully. And we hit Enter there. Now there are some other things we can do with this, but we won't get into that right now. So, there's our patient Class. We just created it. Let's go grab Class again and drop it on. We need an animal Class in this App. We'll just take all the defaults and now we're going to do the same thing again. We're going to right-click and add our Properties. Animal has a name. Notice how quick this is going, huh? Animal has a weight. Right-click the blue, Add Property. Animal has a breed. Then let's talk about Methods. What Methods did the vet say he needs? Well, he has to feed the animal when it's here overnight, so we'll put that in. And he also has to inoculate the animal, so we'll do that. Inoculate this anima. And notice we have two Classes. We have visually added Properties and Methods to these things. And again, a lot more stuff you can do here. It's a very simple example for you. If I go to the Solution Explorer, you will notice that there is now an animal VB Class and a patient VB Class. Here's the real cool part. If I double-click the animal VB Class it has written all the code for me to set this up, the skeletal code. Now, remember when I did the Properties earlier I did a Public name As. That's not really the right way to do it, and this did it the right way, OK, so you'll have to learn about this. But notice it wrote the code for me, OK? Now, I can go back into my Designer and remove the feed Method, come back out here and open up animal and you'll notice feed is gone. Very, very easy to add and take away these Methods. Now, what I'm actually going to do is, I've got to go in here now and add code to make this function the way I wanted it to, OK? So I can say MsgBox, right, Animal has been inoculated Ð probably not spelled right. And if you put the right thing in here that will work. OK? So, let's go back to our Form Design here and let's drag a Button on and I want to show you something here. If we Dim a As New, notice it sees Animal, come down to the next line, hit a, notice we see breed, inoculate, name, and weight, just like we did before. But how cool is it that based on the diagram we didn't have to code all this. We did it visually and it coded it for us. Now, you can do a lot of other cool stuff with this. Notice you can set Inheritance, and all kinds of things. So, sky's the limit here. Just wanted to show you this tool. That is the Class Designer, and this is an incredible tool for building truly object oriented applications where you have some complex relationships between Methods and Classes.

Tutorial Information

Course: Introduction to Microsoft Visual Studio 2008
Author: Mark Long
SKU: 34008
ISBN: 1-935320-54-8
Release Date: 2009-06-26
Duration: 7 hrs / 72 lessons
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available