My Peers ↓ Filter:

5 Jan 2012

Lesson Three

Todays lesson was brilliant, we ended up covering some advanced concepts of coding, specifically OOP! A.K.A. Object Oriented Programming.

Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs.
Source: http://en.wikipedia.org/wiki/Object-oriented_programming

Concepts

Arrays

An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed.


Each item in an array is called an element, and each element is accessed by its numerical index. As shown in the above illustration, numbering begins with 0. The 9th element, for example, would therefore be accessed at index 8.
Source: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

I like to think of an array as a table, a table which can store an arbituary piece of data that can be accessed through its index key. Seb gave a good example of an array, which he stored each our ages and linked them to an associative index, our names. Each age could then be accessed by the persons name.

Functions

A subroutine (also called procedure, function, routine, method, or subprogram) is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code.
Source: http://en.wikipedia.org/wiki/Subroutine

Functions are a fairly simple concept; they allow us to run set pieces of code whenever they're called. For example, we could write a function which you passed two numbers to when you called it and it would add those numbers together and return the answer. The numbers passed could be different each time, but the function would be the same.

Classes and Objects

A class, for example, is like a blueprint for a house. It defines the shape of the house on paper, with relationships between the different parts of the house clearly defined and planned out, even though the house doesn’t exist.

An object, then, is like the actual house built according to that blueprint. The data stored in the object is like the wood, wires, and concrete that compose the house: without being assembled according to the blueprint, it’s just a pile of stuff.
Source: http://net.tutsplus.com/tutorials/php/object-oriented-php-for-beginners/

Using the result of todays lesson, I shall cover an explaination of both classes and objects below.

Result

The below, Stripes, example depicts the use of multiple objects created from one class. The Stripe class is a blueprint for each stripe, technically, that means each stripe is an object. As you can see, the stripes behave and look the same - they've all been created from the same class. When they're created, custom parameters can be passed to change certain aspects of the object; in this case we can give each object an X-Axis position and a colour, which is why you'll notice these are the two differences between each stripe.



In todays lesson, Seb also set us an assignment; I'll cover that in the following post.