Welcome back to Intermediate Visual Basic. This is the third course in the Introduction to Computer Programming with Visual Basic Specialization. In this module, we're going to roll up our sleeves and start developing classes in our code. In the last module, we talked about modeling classes. Now we want to actually write the code that's going to encompass both behavior and the data of a class. Some learning objectives here; when you're done with this module, I want you to be able to implement a class in Visual Basic. I want you to be able to implement the fields in classes, I want you to be able to implement the methods in the classes, and I want you to be able to implement one-to-one has-a relationships in Visual Basic. I'm going to expand on this in future modules where we can do the one-to-many relationships and the is-a relationships but right now, this is what our goals for this module. In this first lesson, we're going to think about coding of classes, data fields, and properties. Just a little definition here about classes and objects. An object is a self-contained unit that has properties, methods, and other members. A class is really the template. It contains the code that defines the members of an object. An object is an instance of a class, and the process of creating an object is what we call instantiation. Now, an important concept we want to have you understand is encapsulation. It's a fundamental concept of object-oriented programming. It lets you control the data and operations within a class that are exposed to other classes. The goal is to hide some of the level of detail so you have some flexibility in future versions of that class without breaking any consumers of your class. To start out, we want to think about how we add a class to a project. If you are using the command line: dot net tools, you want to just create a file with the name of the class and a dot vb extension. In Visual Studio, you can right-click on the project in solution explorer, and add a new item and then choose new class. Then you're going to get this shell. It's going to say, Public Class, and then you give it the name of your class, and then an End Class ends that structure. In this example, myClass is the name of my class, okay? Public fields represent data values associated with an object's instance. What I mean by that is, for each instance of myClass, they'll have a different myCode if you will. Here you'll see myClass is public and myField is public. That means anyone gets access to that class, and to that instance of that code. Now, this is not proper encapsulation, but you can make public fields like this. Properties allow us to essentially hide how we're internally representing the data. Here, you'll see a better implementation. We have myCode is private, as a string within the class. Private means, only members of that class can access that variable and then we have a public property code, that can be accessed by anyone other than an instance of this class and we have a getter and a setter. The getter starts with a get and ends with the end get and always returns a value. In this case, it's very simple. I'm just returning the myCode variable. Okay? The setter takes in a value, and I'm just assigning it to myCode. Now, you might say, this seems like a lot of work for the same thing. But, I'm now free to modify my implementation without someone who's using my class, having to change any of their code. Because I'm hiding my implementation that I'm storing it in a variable, myCode, I can store it in other ways. I might store it in a file, I might store it in a web service, I might do all kinds of crazy things but anyone who's using my sample class will still refer to the property with code. Okay? Now, just a little reminder and visibility. We talked about this in the last class when we were doing our UML. Essentially, visibility is going to reference who can access the member. So public can be accessed from any code, private can only be accessed from within the same module class or structure, and protected can be accessed from any derived class and we'll talk about that in a future class. We'll really focus on public and private at this point. All right, a little review. An object is a self-contained unit that has properties, methods, and some other members. A class contains the code that defines the members of an object, and encapsulations is going to let you control the data and operations within a class that are exposed to other classes. All right, I'll see you in the next lesson.