Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-02-2005, 09:04 AM
kgun's Avatar
WebProWorld 1,000+ Club
 

Join Date: May 2005
Location: Norway
Posts: 5,402
kgun RepRank 3kgun RepRank 3kgun RepRank 3
Default A soft introduction to object oriented programming.

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.
http://www.w3schools.com/js/js_objects.asp

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)

<html>
<body>

<script type="text/javascript">

function person(firstname,lastname,age,eyecolor)
{
this.firstname=firstname
this.lastname=lastname
this.age=age
this.eyecolor=eyecolor

this.newfirstname=newfirstname
}

function newfirstname(new_firstname)
{
this.firstname=new_firstname
}


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

myFather.newfirstname("James")

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

</script>

</body>
</html>

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.
http://www.sitepoint.com/books/phpant1/

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:
http://www.w3schools.com/js/js_onerror.asp

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">
onerror=handleErr
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"
alert(txt)
return true
}

function message()
{
alert("JS code is OK!")
}
</script>

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.
http://www.sitepoint.com/books/phpmysql1/

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://www.w3schools.com/
http://www.w3schools.com/js/js_obj_htmldom.asp
http://www.w3schools.com/jsref/jsref_events.asp
http://msdn.microsoft.com/library/de...scriptinga.asp
http://www.javascripter.net/index.html
http://msdn.microsoft.com/library/de...methodstoc.asp
http://www.javascripter.net/faq/javascr4.htm
http://msdn.microsoft.com/library/de...edsecurity.asp
http://www.hotscripts.com/
http://www.24fun.com/

http://www.php.net/

http://www.mysql.com/

http://www.sitepoint.com/forums/

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.
Reply With Quote
  #2 (permalink)  
Old 12-02-2005, 10:08 AM
kgun's Avatar
WebProWorld 1,000+ Club
 

Join Date: May 2005
Location: Norway
Posts: 5,402
kgun RepRank 3kgun RepRank 3kgun RepRank 3
Default Some links on XP.

http://www.extremeprogramming.org/

http://www.martinfowler.com/
Reply With Quote
  #3 (permalink)  
Old 12-06-2005, 12:45 PM
kgun's Avatar
WebProWorld 1,000+ Club
 

Join Date: May 2005
Location: Norway
Posts: 5,402
kgun RepRank 3kgun RepRank 3kgun RepRank 3
Default Sun Java the next step? Create (draw) great Web Applications

1. Component oriented programming.
Build your code, (classes and iterface) by drag and drop. You simply draw your application.

2. We get it free in Norway with SDN Membership! :-) :-)

Get Your Free Copy of Java Studio Creator ($99 value)

Get Your Free Copy of Java Studio Enterprise ($1,895 value)

Get Your Free Copy of Sun Studio ($2,995 value).

3. Join here:

http://developers.sun.com/prodtech/devtools/free/

4. Easy building.
Binding a new component in a database is as easy as one, two, three.

1. Drag a component into the Editing Area.
2. Drag the link onto the component.
3. The component is linked to the data, and you can work with it.


There is no lack of information and free tools on the internet, the problem is to find the right one.
Reply With Quote
  #4 (permalink)  
Old 12-06-2005, 04:56 PM
WebProWorld Veteran
 

Join Date: Apr 2005
Location: Winter Park, FL
Posts: 605
KeithO RepRank 0
Default

thanks man. been trying to get my head wrapped around OOP for a while and these resouces should help.
Reply With Quote
  #5 (permalink)  
Old 12-06-2005, 11:50 PM
kgun's Avatar
WebProWorld 1,000+ Club
 

Join Date: May 2005
Location: Norway
Posts: 5,402
kgun RepRank 3kgun RepRank 3kgun RepRank 3
Default Two good bookstores

1. Php
http://www.phparch.com/shop_dept.php?itemid=5


2. Java, C++, C# and C etc.
http://www.deitel.com/books/index.html

A much recommended book:
Bjørn Kirkerud: Object Oriented Programming With Simula. Addison Wesley Publishing Company ISBN 0 201 17574 6 Some books are classic. They can not be rewritten.

You can learn OOP by reading code. You do not need the compiler, but here are some links if you want to dig dig deeper:

http://www.hitmill.com/programming/cpp/simula.html
http://www.ifi.uio.no/~cim/cim.html
http://compilers.iecc.com/index.phtml
http://www.idiom.com/free-compilers/TOOL/Simula-1.html Sweeden.

The compiler is still in use and used for educational purposes.

Personally I have it for IBM OS/II. My son compiled and run Simula programs on it when he was 8 years old. And the code was fast, faster than C++ code when we tested it.

OOP without multiple inheritance, private, protected and public variables is quasi OO.

A class is nothing more than a container for methods (functions) and properties (variables). An object is an instance of the class, a place in the computers memory.

By hiding interface in different classes, you can have the same method and properites in different classes. You start from a general class. A sub class inherits functionality from one or more (multiple inheritance) superclasses.

Refactoring become easy with OOP. OOP is especially suited for writing user interface.

This should hopefully be more than you ever need.
Reply With Quote
  #6 (permalink)  
Old 12-07-2005, 12:17 PM
kgun's Avatar
WebProWorld 1,000+ Club
 

Join Date: May 2005
Location: Norway
Posts: 5,402
kgun RepRank 3kgun RepRank 3kgun RepRank 3
Default Is PHP a true OOP language?

The answer to this is no, but it becomes more and more a true OOP language. What is the main difference from a true OOP language as C++?

1. Privacy.
PHP 5.0 is more OO than PHP 4.0 since it opens for privacy of class members.

2. Inheritance.
As far as I know PHP has no multiple inheritance possibility.

3. Pointers and references
If you are used to C++ or Java, a reference in PHP is not the same as a reference in C++ or Java. In those languages, a reference is a pointer to a memory location. So passing a variable by value or by reference is different in PHP. If you intend to link to the original variable, you must pass values by reference. If you pass by value (copy) and the original variable changes, your (copied) variable is not the same as the source variable.

Good Example from the PHP book above in chapter 2. & is the reference operator.

<?php
$color = 'blue';
$settings['color'] = $color; // Makes a copy
$color = 'red'; //color changes
echo $settings['color']; // Displays "blue"
?>

Then note:

<?php
$color = 'blue';
$settings['color'] = &$color; // Makes a reference
$color = 'red'; //color changes
echo $settings['color']; // Displays "red"
?>

So passing by reference allows you to keep the new variable "linked" to the original source variable.

Remember: And C++ like Java is a compiled language, while PHP is interpreted. That means that the same operation is much slower in PHP.
Reply With Quote
  #7 (permalink)  
Old 12-08-2005, 12:37 AM
kgun's Avatar
WebProWorld 1,000+ Club
 

Join Date: May 2005
Location: Norway
Posts: 5,402
kgun RepRank 3kgun RepRank 3kgun RepRank 3
Default OOP in Beta the next level of abstraction.

http://heim.ifi.uio.no/~kristen/FORS..._OO_start.html


KW's distributed objects and OOP in large data base projects.

OOP in Beta http://www.daimi.au.dk/~beta/books.html, http://heim.ifi.uio.no/~kristen/FORS...hovedside.html

is the next level of abstraction.

You can download the book free here:
ftp://ftp.daimi.au.dk/pub/beta/betabook/betabook.pdf

What was the intent of Simula? One aspect was to simulate reality.

So it is poosible to use people to simulate behaviour. Each person represent a class with properties and functionality. When persons interact in the play, the project is simplified and simulated.

This paper describes abstractions that have been designed to support distributed programming in the object oriented programming language BETA. The approach is minimalistic in the sense that a goal is to provide the essential building blocks on top of which other distribution related abstractions may be built. This goal is made easier by demanding for type orthogonal persistence and distribution as the full power of the underlying language may then be used when building higher level abstractions on top of the basic ones.

Download the paper in postscript here http://www.daimi.au.dk/~beta/Papers/....abstract.html
(can be converted to PDF with Acrobat reader 7.0 Professional)

Related link:
http://www.daimi.au.dk/%7Ebeta/doc/f...guage-faq.html

In a nutshell, Beta is about minimalism, even if the language is very compact and a large project may be complex.

P.S. References in PHP 5.0 is more like references in Java and C++. Even if PHP is interpreted, you may reduce load on your databaseserver by using Aggregation and / or Polymorphism. Read about it in chapter 2 and 3 in the Sitepoint book cited above.
Reply With Quote
  #8 (permalink)  
Old 12-08-2005, 09:24 AM
kgun's Avatar
WebProWorld 1,000+ Club
 

Join Date: May 2005
Location: Norway
Posts: 5,402
kgun RepRank 3kgun RepRank 3kgun RepRank 3
Default How do I build my own dynamic CMS using OOP?

As I wrote above, OPP is very good at creating great interface. On a high level it is about making the right data structures, connection classes, set and get methods, containers and iterators on these containers.

Start by using PHP and MySQL. Build your own small CMS. When you are clever at that, you may go to the next step and use Sun Java and “draw” your application. You start by creeping, then walking and at last running.

If you get very clever, you use XP techniques and writes the tests before you write anything else. In a large distributed system, you may need Beta.

The sky, your fantasy and creativity set the limit of your ability to write large dynamic databasedriven systems. I have given you some tools and references above.

Content and code is Queen. Refactoring is King.
Reply With Quote
  #9 (permalink)  
Old 12-08-2005, 01:35 PM
kgun's Avatar
WebProWorld 1,000+ Club
 

Join Date: May 2005
Location: Norway
Posts: 5,402
kgun RepRank 3kgun RepRank 3kgun RepRank 3
Default More precise on Concurrency and BETA.

Modern computer hardware often consists of a large number of processors connected through some communication media, an example being a set of workstations connected through a local area network. The concurrency described in a BETA program may be realized through time sharing on a single processor, or by distributing the active BETA objects on a number of processors.
Source: ftp://ftp.daimi.au.dk/pub/beta/betabook/betabook.pdf

page 17 and 18.

And this is important:

BETA replaces classes, procedures, functions and types by a single abstraction mechanism called the pattern. It generalizes virtual procedures to virtual patterns, streamlines linguistic notions such as nesting and block structure, and provides a unified framewor for sequential, coroutine and concurrent execution. The resulting language is smaller than Simula in spite of being considerably more expressive.
Opt. cit. page 18.

Kw's: A single abstraction, called the pattern.
Reply With Quote
  #10 (permalink)  
Old 12-10-2005, 12:28 PM
kgun's Avatar
WebProWorld 1,000+ Club
 

Join Date: May 2005
Location: Norway
Posts: 5,402
kgun RepRank 3kgun RepRank 3kgun RepRank 3
Default Some remarks before I leave.

1. What is Simula?
The Norwegian company Simula has as far as I know, no relationship to the American .


2. The Simula definition of an object.
An object is an entity which may contain data (variables, arrays), operators (procedures, functions) and actions (imperatives). The data and operators of an object are said to be its attributes. A class is a special Simula construct that is used to declare a pattern (or template) for a set of objects that are similar in the sense that they contain the same attributes and imperatives. Objects that conform to the pattern of a given class are generated (created) when special object-generating expressions are evaluated.

We note that pattern that is a fundamental concept in Beata, is already mentioned in the above definition of a Simula object.
Reply With Quote
  #11 (permalink)  
Old 04-20-2006, 11:56 AM
kgun's Avatar
WebProWorld 1,000+ Club
 

Join Date: May 2005
Location: Norway
Posts: 5,402
kgun RepRank 3kgun RepRank 3kgun RepRank 3
Default

By downloading and installing XAMPP in a few minutes, you have an excellent platform to learn OO PHP. Even Big Blue is concerned about the power of XAMPP

I can reccomend The PHP Anthology: Object Oriented PHP Solutions

They teach you OO PHP.

The power of PHP is:
1. Very large user base.
2. Good documentation.
3. Large communities.
4. 99% of your problems may be solved if you find the relevant class libraries.
5. Free platform.
6. Simple.
7. You can embed PHP code in URL's.
8. A good platform to more advanced programs.
9. You can switch in and out of PHP.

<HTML>

<?php Some statements ?>

HTML or JavaScript code etc.

<?php Some statements ?>

HTML or JavaScript code etc.

............................
............................

<?php Some statements ?>
</HTML>

Powerful, dynamic and effective.
Reply With Quote
  #12 (permalink)  
Old 04-22-2006, 06:36 PM
kgun's Avatar
WebProWorld 1,000+ Club
 

Join Date: May 2005
Location: Norway
Posts: 5,402
kgun RepRank 3kgun RepRank 3kgun RepRank 3
Default Talking with myself in this post.

Here is an example of Generic algorithms in C++. It paramtrizes software. Quite general. When you understand this code, you have reached a higher level.

/*

GENERIC.CPP: Example of generic algorithms. Templates and generic algorithms.

Source: Andrew Koenig: "Templates and generic algorithms" Journal of objectoriented programming june 1994 page 46 and "Generic iterators" Journal of objectoriented programming, september 1994 page 69.

*/

#include <iostream.h>

template<class Ptr, class T> Ptr find(Ptr array, Ptr beyond, const T &x)
{
Ptr p = array;
while (p != beyond && *p != x)
++p;
return p; // Returns the address!!
}

template<class Ptr> void reverse(Ptr start, Ptr beyond)
{
while (start < beyond ) {
--beyond;
swap (*start, *beyond);
++start;
}
}

template<class T> void swap(T &x, T &y)
{
T t = x;
x = y;
y = t;
}

int main(){
int x[] = {1,2,3,4,5,6,7,8,9,10};
int y[] = {1,2,3,4,5,6,7,8,9,10};
reverse(&y[0], &y[10]);
int i;
for (i = 0; i <= 9; ++i) {
cout << "x[" << i << "]" << " = " << x[i] << endl;
cout << "y[" << i << "]" << " = " << y[i] << endl;
}
cout << endl;
cout << "Finds 8 in x at Hex address: " << find(x,&x[10],8) << endl;
cout << "Finds 8 in y at Hex address: " << find(y,&y[10],8) << endl;
return 0;
}

For a theoretical explanation see:

Gordon Blair, John Gallagher, David Hutchison and Doug Shephard (1991): "Object Oriented Languages, Systems and Applications." Pitman Publishing ISBN 0-273-03132-5

Chapter 1 - 5, especially chapter 5.


An example of exception handling in C++:

/*

C++ Report October 1994 page 72.

PUZZLE.CPP: Problems with exception handling.


*/
#include <exception.h>

int main()
{
void f(int i)
{
if (i<=1) throw 1;
try {
f(i-1);
} catch (int c1) {
try {
f(i-2);
} catch (int c2) {
throw c1+c2;
}
}
}
return 0;
}
Reply With Quote
  #13 (permalink)  
Old 04-23-2006, 08:38 PM
kgun's Avatar
WebProWorld 1,000+ Club
 

Join Date: May 2005
Location: Norway
Posts: 5,402
kgun RepRank 3kgun RepRank 3kgun RepRank 3
Default The low hanging fruit of ASP.net.

We are incredibly excited to announce that effective April 19th, 2006, all Visual Studio 2005 Express Editions including Visual Basic, Visual C#, Visual J#, Visual C++, and Visual Web Developer Express will be free permanently!
Source:ASP.net

May be Microsoft had to do it. Sun Java is a great plattform. XAMPP for Apache + Linux + PHP + MySQL + PHPAdmin ++ are open source and free. According to Visual Studio Express Announcements it is now free. That means that you can get a stripped down platform to learn ASP.NET, Visual C#, Visual C++ etc. That is good enough:

With all these advantages, ASP.NET has relatively few downsides. In fact, only two come to mind:

- ASP.NET is a Microsoft technology.
- Serious ASP.NET developers requires an understanding of object-oriented programming.

Source: Build Your Own ASP.NET Website Using C# & VB.NET page 5.

ASP.NET pages are compiled, while one of the biggest competitor PHP (XAMPP based on Apache (Linux), PHP, MySQL etc.) is an preprocessor or interpreter. Code is interpreted by the web server and sent to the browser. PHP is a very loosely typed language. That gives felxibility. The main difference is however binding. Compiled code is bound at implementation time, while interpreted code are bound at run time. Run time binding is more felxible.

Let us say, you have a shopping chart program that resides in primary storage, that is memory. If the code is compiled, you can think of it as a table. That table is fixed. The connections between different classes are fixed. Run time binding on the other hand implies that the code lives and changes in memory depending on the objects being created at run time.

The low hanging fruit of PHP is listed in another WPW thread.

Download Visual Web Developer 2005 Express Edition.

You find a lot of ASP links in the sticky Programming Resources, Tutorials, etc

No need for me to repeat.

So now you have three competing platforms:
ASP.NET
XAMPP
Sun Java

The choice is yours.

Note in some situations, Java Script (that is browser dependent) gives greatest flexibility. Then we are back to where this thread started.
Reply With Quote
  #14 (permalink)  
Old 07-05-2006, 08:28 AM
kgun's Avatar
WebProWorld 1,000+ Club
 

Join Date: May 2005
Location: Norway
Posts: 5,402
kgun RepRank 3kgun RepRank 3kgun RepRank 3
Default

Still talking to myself. This thread:

Why PHP?

should be a WPW classic.
Reply With Quote
  #15 (permalink)  
Old 09-29-2006, 06:36 PM
kgun's Avatar
WebProWorld 1,000+ Club
 

Join Date: May 2005
Location: Norway
Posts: 5,402
kgun RepRank 3kgun RepRank 3kgun RepRank 3
Default The gang(s) of four.

This

Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides (1995): "Design Patterns: Elements of Reusable Object-Oriented Software." Addison-Wesley Professional ISBN 0201633612

often cited reference, is referred to as the gang of four in OOP and regarded as a must reading.

There is at least, IMO, another gang of four:

Gordon Blair, John Gallagher, David Hutchison and Doug Shephard (1991): "Object Oriented Languages, Systems and Applications." Pitman Publishing ISBN 0-273-03132-5

and a gang of three

Ole Lehrmann Madsen, Birger Møller-Pedersen and Kristen Nygaard ( 1993): "Object-Oriented Programming in the BETA programming language". Assn for Computing Machinery. ISBN 0201624303

Se OopSchool.com for more information.
Reply With Quote
  #16 (permalink)  
Old 10-10-2006, 03:49 PM
WebProWorld New Member
 

Join Date: Oct 2006
Location: Seattle, WA
Posts: 2
boltz RepRank 0
Default

http://safari.oreilly.com/0596007124 is great for someone that has a decent understanding of OO programming, but doesn't quite get it. The way they present the information is really, really good and their descriptions of patterns make sense.