I'm trying to understand the basics of how Object Oriented Programming works with C++. I'm not really trying to learn the language per-say (although I might be interested in learning it gradually). I brought two books on C++ and read through them once, and while some things seem to be easy to understand, setting of variable types, creating statements and function ex. when the books start getting into Object Oriented details it becomes a little confusing. I want to see if my basic understand of C++ if correct:
You basically start with Classes. A simple class contains variables and functions that allow the class to specialize in a specific operation. A class also allows only those variables and functions (i guess you can call them inputs and outputs in a sense) that let it interact with other data to be public. Other variables and functions that are just the inner workings of the Class are keep private so that other classes and data can't mess around with the Class' operation. For example you have a Class called "Fish". This class contains all the functions and variables that it needs to simulates any type of fish in 3-D. Certain functions and variables, like how the geometry is built and rendered in 3-D, is kept private, because it not important for the outside world to know. The only thing the outside world needs to know is those variables that make a fish a certain type, like "number of fins, weight of body, carnivore or vegetarian, color and so on.
Next comes Objects. Objects are a variable with a class type. For example, you just finished making your "Fish" class and now you want to use it to make a specific type of fish. You want to make a "Gold Fish", this Gold Fish references the fish class with it set of values. For instance a gold fish can have fish values of ""number of fins = 3, weight of body = 1.5, vegetarian, Color = Gold and so on. These values are sort of sent through the Fish Class' functions, and the Fish Class creates the Gold Fish based on those values. More Objects give more fish and different values for each object gives me different breeds of fish.
Now on to Inherence. Inherence allows you to assemble a bunch of objects together to form a bigger picture. For instance you want to make a 3-D fish again, but you want this fish to have behavior and movement. There are a lot of different aspects in a fish's behavior and movements that vary heavily from fish to fish. So rather then make one huge class, you break up the fish into a number of specialized Classes. Lets say you make one class that specializes in how the fins are shaped and how they behave. Another class that looks at how the mouth of the fish is shaped and how that behaves, another class that specializes in the eyes, another for drawing the geometry in 3-D...and so on. Now that you have all you different classes, you want to make objects (that contain the values for the type of fish you want to simulate) of those classes and assemble it. To allow different objects to combined you need to let higher objects pass (or inherent) their functions to lower objects. For instance you have this fish, and every part of the fish needs to be drawn out as geometry. The "Draw Geometry" Object needs to pass its capabilities to all the different fish parts. The Draw Geometry acts as "the parent object" and it passes it attributes to its "child objects" which are the mouth, fins, eyes. Above this parent object there might be another parent object "XYZ". This object tells the location of where we want our fish to be in 3-D. Since all the parts need to move together this peace needs to pass its function to every object. You can say that this "XYZ" object is the parent of the "Draw Geometry" object and the grandparent of the "mouth, fins and eyes" objects.
After Inherence comes polymorphism (the one I totally don't understand). How it works is a mystery to me, and I hear that there are eight different types of polymorphism. From my understanding, polymorphism is when you pass different types of value types between objects, and the object changes the type passed to it or the object receiving the values adapts to the data type being sent to it. Illustrating the idea:
Float Dog.Bark ----> Int Soud.Speak (Float Sound.Speak)
Here, we have a Dog Object with a "Bark" variable. The Bark variable is of type Float. The output of this variable is sent to the input of the Object Sound. Speak. The "speak variable is of type Int. The Sound Object decides to adapt the using floating point numbers so that it can use the outputs of Float Dog.Bark
For some reason this doesn't sound correct to me. My other idea of how it works is that an objects function is override by another objects function. But i can't understand how that would work.
My last thing is on what is a C++ (or sometime there called API) library. Is it just a bunch of class made by different programmers so that other programmers can use them in their code?