Classes - Let's be objective!

What are, why use classes?
First off let me admit, this is one that I struggled with and I am not sure why.
I could never really grasp the concept of classes, possibly because I never really found anything that explained it this way.
What brought me to the true understanding was tree views.
Without classes, populating a tree view is a mundane effort at best. With classes, each treenode can be a class object. This makes it very easy to do tree views since each node will contain all of the childnodes as class objects and all of their inherent properties.
Next was databases.. same concept. Each row in a database is basically a class property.
Think of a class as an object, a sort of variable with multiple properties.
What is nice about this type of object is that you can pass all the little gooey details in a single object. (one of the O's in OOP)
That would make it a variable that is filled with other variables that you call by a name.
So you have a car. It is an object.
That car is filled with other variables... color, style,make,model and serial number.
When you pass that car around from a programming perspective, all of those other variables come with it.. easy peasey.
So think of the class as the factory... where they build the cars.
Lacking valid syntax, extremely specific and for context only..
  • Object:Car
    • String:Color
    • String: Make
    • Int: MPG
    • List: Options
Each one of those internal varialbes make up the complete Car and are called the properties of the class Car.
The class itself (or in this case, the factory) does all of the "car property" work.
It builds the car by populating all of those variables.
It also provides methods/functions to get the cars and set the values of the properties, which in this case would be used (consumed) by the dealership.
Get - means you are getting the property, Set - means you are setting the value of the property.
(I will describe private versus public properties of a class in another page.)

An example would be that the class itself can build a list of cars for shipping.
The dealer says that I need to get my new year models, so send me a list of cars that are mine.
This would come across as:
List 2018Inventory and the factory would compile that list but having a method that takes all of the required car objects, packs them in the list and then sends that complete list loaded with cars to the dealership.
So to extend our class, we would add a method like GetNewStock(string dealership){ }
The dealership would then call the method:
List newStock = new Car.GetNewStock(MyDealtershipsCode);
When the dealership calls that method, it knows that the list will contain all the valid cars for the dealtership.
It can loop through that list and use each car object, knowing that car1 will have all of the variables listed above.
Knowing that options are a list as well, it can loop through all of the options of the Car object.
So something like:
foreach Car currentCar in newStock
foreach option in currentCar
print option
or using an integer loop...
for (int i1=0; i < newStock.Count;i1++)
for (int i2=0; i < newTock[i1].Options.Count;i2++)
print option[i1].Option[i2]
Now build the classes (factory) can get complex, but calling the class makes coding substancially easier.
That is why I created this Class Builder application. It provides an easier way to build these classes by doing all of the get/set work for you.
Video is no longer available due to demonetization
It allows you to easily create these classes using a database model in both SQL, MySQL and even Active Directory.
It will query the database and build a class that matches the database.


Where this also comes in handy is when building and using API's to get this data.
These objects (Cars) can be serialized and passed via an API/WebService to an API consumer.
You easily export to json, soap, etc.
That way, the person consuming the API gets the same Car class object using json that say a method using the class in an internal application.
Same Car, same variables and typs of properties.