Classes and Object Oriented Programming





What is a class?

There are many ways to discuss and make analogies to classes. I will use the analogy of bicycles. We could say that a bicycle is an instance of the class known as bicycles with various subclasses, road bikes, mountain bikes, etc. Once you make a class and all of its methods you would have a "blueprint" from which you could make thousands of bicycles.

Example

The following Bicycle class is one possible implementation:

            Screen Shot

The output from the Terminal:

      Screen Shot


Benefits

One of the benefits of Object Oriented Design is that to make a change to the design or "blueprint" you would only need to make a change to a couple elements rather than needing to change everything. In a non-Object Oriented Design model if you change one thing you would have to change everything else that follows that change as well. The change and its effects would cascade through the entirety of the code, and you might need to change many lines of code.

This also addresses the idea of specialization and separate functionality, so if you make changes to one it would NOT affect the other. As Wikipedia humorously stated through Richard Conway,
"So, for example, one would know that the square root function was separate from the launch missiles function, and a change to one could not affect the other."



Resources

Wikipedia's description of Object Oriented Programming

A description of classes by Oracle. Java and other languages also have classes.