In this video, we'll learn a little bit more about classes and objects.
You can think of classes as blueprints from which objects are created.
Classes are user-defined types.
And one of the goals in object-oriented programming
is to make the user-defined types feel like they're part of the programming language.
So when we create our classes,
we want to be able to use them, just like we use integers, doubles and so forth,
easy and simple.
Classes have attributes which are data.
And they also have functions, which are called methods.
As mentioned in the previous videos,
classes can hide data and methods that are only used internally by the class.
This is done using the private and public access modifiers.
The goal of a class is to provide a well-defined public interface
that the user of the class can easily use to solve their problem.
Here are some example classes:
account, employee, image, standard vector and standard string.
These are all classes that model real-world entities.
Vector and string are part of the c++ standard library.
Account, employee and image might be classes that we would create in our applications.
Okay. So now that we know what a class is, what's an object?
Well, objects are created from classes and represent a specific
instance of the class they're created from.
So if I have an account class, I can create a Frank's account object
that's a specific instance of an account that models Frank's account information.
We can have as many objects as we need.
If we were modeling a real banking application,
we could have hundreds of thousands of account objects,
each representing an individual instance of an account.
Each object has its own identity,
and each can use the methods defined in the class.
Let's see an example.
We know that ints and doubles are primitive types in c++.
They're not classes, but this analogy will help make a point.
In the first two lines, we define two integers, high score and low score.
What does that tell us? Well, it tells us what the valid values are for those variables,
and it also tells us the operations we can perform on those variables,
for example, addition, subtraction, multiplication and so forth.
Again, integers are not classes.
But just for a moment, think of int as the class
and low score and high score as objects created from the int class.
Notice that low score and high score are instances of integer.
They each have a value, and they each have an identity.
Now look at the next two lines.
Let's assume that we've already written the account class, and it's a true c++ class.
Notice the syntax and how similar it is to the syntax for the integers above.
Account is a user-defined type.
So Frank account and Jim account are instances of the account class,
they are objects.
Each of these objects has an identity and values associated with them,
just like high and low score did.
This should look familiar since we've already been using objects all along.
The last two lines create a scores object
that's an instance of a vector of integers
and a name object that's an instance of string.
Okay. So now that we know a little bit more about classes and objects,
let's see how we can declare a class in c++ in the next video.