Web Programming Header

INFO PAGE

Object Oriented Programming Theory

Object Oriented Programming or OOP is a metaphor used by most progamming languages. It models life in that things are objects (nouns) with properties (adjectives) and they have methods of doing things (verbs). Let's take a step back and tell a story.

PATTERNS


Just like in real life, patterns are things that repeat. Dots that repeat make a polka dot pattern ;-) When we can make a template we have a pattern - as in a pattern for a dress. In coding it is the same - coding is made up of all sorts of patterns: These patterns have been assimilated by the programming language and as such we do not refer to them as patterns but just the language.

LANGUAGE

The object oriented pattern is such an established pattern that we usually consider it as the language as well. It really is like a language on top of a language as it is written on top of the programming basics. Some history...

PROCEDURAL CODING

In the early days of coding we dealt primarily with numbers and strings (text). To this day, in many languages (such as JavaScript) numbers and strings are called primitives ;-). Coding was procedural and went step by step using a goto command to repeat code. We recognized life's patterns as we started modeling (mimicking) life with code. Things in life are divided up into objects with properties and methods to do things. These patterns matched patterns in our main language with nouns, verbs, adjectives, etc.

ABSTRACTION

A main pattern - a meta pattern - is to recognize that there are patterns. The act of recognizing patterns is called Abstraction. So, we made a language in which objects can be made from patterns. The patterns in the language are called CLASSES. A class is the template from which an object is made. The class defines the properties and methods of an object - termed its members. (Methods are stored as properties - so properties will do as well).

Abstraction diagram with composition (ands) and classification (ors) in boxes with an overlayed hierarchy

INHERITANCE

We also recognize that a class can have sub classes and super classes. Sub and super just mean below and above referencing a hierarchy diagram with node 0 at top. A sub class has all the properties and methods of the base class plus its own. An object made from a class is said to inherit the members of the super class.

COMPOSITION

An object can be composed of properties - a person object is composed of a head, legs, etc. The head, legs, etc. DO NOT inherit from the person as they are not a type of person rather the person is composed of these parts - this is composition, not inheritance. Classification lets us pick what to make and composition lets us make the object out of parts.

COLLECTIONS

CONCLUSION

Object Oriented Programming was created by very logical people to model life, hence it is very much a philosophy and I treat it as such (Nodism). OOP models life through a mix of classification and composition. Classification describes the types of things there are (this OR that). Composition describes the parts of things (this AND that).