Re-Using Classes / Fundamentals of Class Design
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
If you are new to Visual Basic, and this is the first time you've done very much programming and you are beginning in .NET. I need to point out some class design fundamentals. Now when you first get your hands around classes a pretty fascinating designs and you can see that by putting functionalities into a class you can create some pretty elaborate objects. But let's talk about some class design fundamentals. Now keep in mind the whole point of object oriented programming was to simplify the process. Number one to make our programs run more efficiently and even more importantly to make them be written more efficiently; that we don't write duplicate code and then we don't have copies and copies of code all over the place in our programs. And so simplicity is the overriding factor on everything. First of all when you name your class, make sure that you use a name that describes very distinctly what the class does. Be more careful about naming classes, these bizarre names that they sound real techy. But they don't really describe the class itself and what's really happening. For example a class that we use to instantiate objects to manipulate student issues should be named student. Just, just keep that in mind. Then functionality - now this is a big one. If there is one thing that programmer types tend to want to do is build this one end all class that does everything. And there is some general rules here and that is, as a general rule now, as sure as I say this you know people will have three million reasons why this is not a good rule. So understand, these are general guidelines and you may have every legitimate reason to evaluate this. As a general rule your class should have around half a dozen public members. Now a member is any kind of functionality that a class has, basically it would be properties or fields or methods - anything that's going on, anything that can be done with the classes is considered a member. So about half a dozen of those. If you find yourself going past that, you are probably creating a class that's too complicated or just doing too many things. Now properties and methods are generally what we are going to put in here. And again watch for this half dozen limit. And this includes both properties and methods. Now the next thing is encapsulation and abstraction, and remember always remember that we want to encapsulate as much information as possible away from the user. We only want to collect as much necessary information as we have to have to give this class it's functionality; and for example variables that we need to control inside the object should be created as private. And we'll talk about the different access specifiers a little bit later on in the course. Generally if we, the more we hide from the user the more simplistic the class and its functionality looks. Now we maybe going around the world inside there to do some really cool things but let's encapsulate the details away from the user. Another course closely related to that is abstraction. We want to abstract as much of what's happening as possible away from the user. We want the user to enroll in a course, to just simply call the enroll method and pass some data. We don't want them to be concerned with databases and connections and that sort of things, so encapsulation and abstraction - always keep those in mind. Now the next thing is public and private, be real careful, keep in mind that anything that is declared as public in a class can be seen and utilized and manipulated from outside the class. So if you've got a method that you never want to have anybody call from outside the class, it's only for functionalities of other methods inside, declare that thing as private. We are back into this encapsulation, abstraction type discussion there. But make sure that you are real diligent in the use of the public and private specifiers on your methods especially, especially on your properties. As a matter of fact it's really not encouraged and we are going to look at properties a little bit later to use variables as properties. We really should be using fields and this is where we programmatically set our variables, and return our variables. So you'll see that in a couple of videos. So when we get to the properties section, we are going to do couple of videos, one's called global and ones called fields and I'm going to show you both of these. And fields are really the correct safe way to go with class design. Keep in mind in review the main thing we are looking for with class design is that we provide the user a very simple straightforward way to carry out some functionality. We want to hide the inner workings of it, we want to abstract the complexity away from them, we want this thing to be named and described in such a way that it is very easy and simple to use. And also the more generic that we can make this thing the better the chances that it can be reused in other programs. So keep those general guidelines in mind.
Tutorial Information
| Course: | Microsoft Visual Basic .NET |
| Author: | Mark Long |
| SKU: | 33433 |
| ISBN: | 1932072349 |
| Release Date: | 2003-05-27 |
| Duration: | 6 hrs / 87 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
United States 