A soft introduction to object oriented programming.

Site Admin
Posts: 88
Joined: Tue Jan 31, 2006 3:10 pm
Location: Moss Norway

A soft introduction to object oriented programming.

Postby KBleivik » Wed Feb 01, 2006 5:45 pm

1. Introduction.
By using the JavaScript Create Object, you can get a soft introduction to object oriented programming (OOP).

The resources at W3Schools, where you can learn the basics of nearly all web design are excellent. It has an inbuilt editor where you can modify example code and see the effect immediately.

2. Start.

Read that section and click on the examples (takes 5 to 10 minutes).

- Create a direct instance of an object.

- Create a template for an object.

In the last example modify the code in the left window to: (Modifications in bold)


<script type="text/javascript">

function person(firstname,lastname,age,eyecolor)


function newfirstname(new_firstname)

myFather=new person("John","Doe",50,"blue")


document.write(myFather.firstname + " is " + myFather.age + " years old.")



and click the button "Edit the text and click me".

Note the difference.

3. Exercise.
Write a function that changes the persons age, set the new age to 60 and submit the change.

Now you have a vague idea of OOP.

4. Next step.
Download free the first three chapters of the book "The PHP Antohology: Object Oriented PHP Solutions , Volume 1." by Harry Fuecks from SitePoint.

Chapter 2. Object Oriented PHP explains how you may make your own page object. Then you can add the properties and layout you want to that object and make your own page templates, eg. a table with three tables for header, body and footer with different properties etc.

Once you understand OOP, you will love it.

Also start your first step on Extreme Programming XP, by writing the tests of your code before anything else:

Exapmle: Again we use the resources at W3schools:

Use the code in "The onerror event" example to write a test to test for JS errors on the page.

Copy this code:
<script type="text/javascript">
var txt=""

function handleErr(msg,url,l)
txt="There was an error on this page.\n\n"
txt+="Error: " + msg + "\n"
txt+="URL: " + url + "\n"
txt+="Line: " + l + "\n\n"
txt+="Click OK to continue.\n\n"
return true

function message()
alert("JS code is OK!")

in the head section and this code in the body section before your own code:

Write this code in the body section:
<input type="button" value="View message" onclick="message()" />

You may improve the test by using JS Try...Catch and Throw statements.

5. An introduction to OOP PHP and MySQL.
From SitePoint you can also download free the first four chapters of the book: "Build Your Own Database Driven Website Using PHP and MySQL" by Kevin Yank.

Learning this technique you can buld you own content management system, and refactoring and you get full control over refactoring and updating.

Note: The great difference between PHP and JavaScript (JS) is that JS code is interpreted by the browser (on the client's Pc) and PHP is interpreted by the webserver. Therefore, the advantage of JS is more flexible dynamic bahavior (action when the mouse is moved) while the disadvantage is that JS is browser dependent.

Some useful links:
http://msdn.microsoft.com/library/defau ... ptinga.asp
http://msdn.microsoft.com/library/defau ... odstoc.asp
http://msdn.microsoft.com/library/defau ... curity.asp




Code is Queen, refactoring is King.

Recommended book: "The Design and Evolution of C++" by Bjarne Strostrup. ISBN 0-201-54330-3

That book takes to a new level in OOP.

6. Additional resources at OopSchool.com.
You find additional resources at:
Kjell Gunnar Bleivik
Make it simple, as simple as possible but no simpler: | |

Return to “Generally”

Who is online

Users browsing this forum: No registered users and 1 guest