iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar 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.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-02-2005, 09:04 AM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
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
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
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
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
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: 616
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
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
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
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
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
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
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
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
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
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
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
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
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
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
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
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
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
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
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
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
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
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
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.
Reply With Quote
  #18 (permalink)  
Old 10-17-2006, 01:06 AM
Easywebdev's Avatar
WebProWorld Veteran
 
Join Date: Apr 2004
Posts: 310
Easywebdev RepRank 1
Default Re: Is PHP a true OOP language?

Quote:
Originally Posted by kgun
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.
Hi Kgun, been a while since I posted anything but just wanted to add a bit to this thread.

I don't know if you looked at php 5.1 yet but it now has excellent OO support. Private and protected class member variables, multiple inheritance and objects automatically passed by reference.

No pointers but when you are not manipulating memory you dont need them.
__________________
"I have not failed. I have found 10,000 ways that don't work" - Thomas Edison.
"The secret to creativity is knowing how to hide your sources" - Albert Einstein.
Reply With Quote
  #19 (permalink)  
Old 10-17-2006, 08:24 AM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default Re: Is PHP a true OOP language?

Quote:
Originally Posted by Easywebdev
Hi Kgun, been a while since I posted anything but just wanted to add a bit to this thread.

I don't know if you looked at php 5.1 yet but it now has excellent OO support. Private and protected class member variables, multiple inheritance and objects automatically passed by reference.

No pointers but when you are not manipulating memory you dont need them.
I did not know that it support multiple inheritance. That is great news. What about namspaces? See thread in my last post above.

PHP6 - Direction of PHP

Have you read that thread? At present I am looking at PHP's image functions and classes. Exciting area. There is also a thread about that above.
Reply With Quote
  #20 (permalink)  
Old 10-20-2006, 10:48 AM
Easywebdev's Avatar
WebProWorld Veteran
 
Join Date: Apr 2004
Posts: 310
Easywebdev RepRank 1
Default

I dont really see a need for namespaces in php. A lot of php programmers seem to have problems with variable scope (hence the furore when register_globals was deprecated) adding namespaces into the mix would only serve to confuse further.

You can accomplish the same funtionality with static class variables to avoid variable name collisions.

C++
Code:
namespace square
{
  int x = 5;
  int y = 10;
}

namespace rectangle
{
  int x = 5;
  int y = 10;
}

int main () 
{
  using square::x;
  using rectangle::y;
  cout << x << endl;
  cout << y << endl;
}
PHP
Code:
class square
{
  static $x = 5;
  static $y = 10;
}

class rectangle
{
  static $x = 5;
  static $y = 10;
}

echo square::$x;
echo rectangle::$y;
The only reason I can see to include namespaces in php would be to be able to write your own versions of php functions in a library file and use "using namespace my_lib;" its something that would be nice to have but not majorly important I feel.

I would rather see php move to a typed language. No more "$i = 1;", "$i = '1';" rather "int $i = 1;", "string $i = '1';" and have php spit an error when you assign a string to a variable declared as an int.
__________________
"I have not failed. I have found 10,000 ways that don't work" - Thomas Edison.
"The secret to creativity is knowing how to hide your sources" - Albert Einstein.
Reply With Quote
  #21 (permalink)  
Old 10-20-2006, 11:34 AM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default

But making a namspace a class was left in C++ (see my link to WPW post about namespaces above), but may good enough in PHP.

Namespaces becomes more and more important the more third party class libraries that are constructed. There are already quite a few.

Here

Testing Conformance to Web Content Accessibility Guidelines

is another PHP OOP thread where you may give valuable feedback.

It is about accessibility classes in an early stage. Do you know if some such classes are already made?

And here is another:
Need help developing DynamicToolbar.net.

is a related thread where you may contribute.

You know PHP better than me, but I am picking up. It is easy compared to C++ :-)
Reply With Quote
  #22 (permalink)  
Old 11-23-2006, 06:14 PM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default

The related links to this thread continues to grow. Here are two new:

OOP in PHP and MySQL tips: Start here.

I've been told that my Perl, CGI, MYSQL site is obsolete
Reply With Quote
  #23 (permalink)  
Old 11-24-2006, 05:17 AM
WebProWorld Pro
 
Join Date: Sep 2005
Location: Manchester, UK
Posts: 254
mikesmith76 RepRank 0
Default

Any more information about how multiple inheritence will work in PHP? My first adventure into programming came from Java, where multiple inheritence was not available and frowned upon. Are we literally talking about something like

class C extends A, B{
}

With both the functionality of A and B combined. What happens if both classes declare the same function?

Time for me to find and read the PHP6 developers minutes me thinks :-) :-)
Reply With Quote
  #24 (permalink)  
Old 11-24-2006, 05:21 AM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default

Yes, multiple inheritance will say that a sub (child) class inherits structure from (extends in PHP) more than one super (parent) class.

In BETA, everything is as described above a pattern.
Reply With Quote
  #25 (permalink)  
Old 03-15-2007, 02:03 PM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default

AJAX is a great exasmple of a technology combining JavaScript OO (see start of this thread) with serverside OO (PHP, Java, .NET etc.)

On the IBM AJAX forum, I found a post with the following title: "A Great AJAX Example" where you can download the JoyiStar AJAX WebShop 3 Beta2 sourcecode free.

After download, unzip or install it and open the example projects(including Java, C#, VB.Net and PHP) and run it, you will get the same looking as you see at http://219.153.35.21:8080

It is nearly 100 Mb code.

"The JoyiStar WebShop is the AJAX web development tools released by JoyiStar corporation. It provides an efficient OOP developing method to construct stable and convenient RichWeb applications based AJAX component".

The application is developed in China:

"AJAX WebShop 3 won the prize of "Golden Software" in China"

I have observed the following:
Sitepoint, an Australian forum, is in the front on OO PHP. Romania is in the front on AJAX and now China. Object oriented programming is getting more and more global and AJAX may be a great driver.

Note: If you try the online example, it may not function properly in all browsers, so try it in another browser if it does not function in your default browser.

My impression is that the application is developed in FireFox, since it functions best in that browser.
Reply With Quote
  #26 (permalink)  
Old 03-22-2007, 11:36 AM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default Multiple inheritance in JavaScript.

Nicholas C. Zakas, Jeremy McPeak, Joe Fawcett: "Professional Ajax" (Second edition) is a great book.

Nicholas C. Zakas page has a lot of resources on the download page. I will draw the attention to the floowing two downloads:
  • zInherit 1.0: A JavaScript library to add multiple inheritance support to JavaScript.
  • zXml 1.0.2 A JavaScript library for cross-browser XML, XPath, and XSLT support.
The use of the zXML library is explained in the above mentioned book. That library can save you much pain and coding if you develop AJAX applications for different browsers.

There are also a lot of articles on the download page that may be of value to you.

At the same time, another OOP language, Ruby is being developed.

"Ruby is a reflective, dynamic, object-oriented programming language. It combines syntax inspired by Perl with Smalltalk-like object-oriented features, and also shares some features with Python, Lisp, Dylan and CLU. Ruby is a single-pass interpreted language. Its main implementation is free software".

Links:
Reply With Quote
  #27 (permalink)  
Old 07-04-2007, 01:56 PM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default Re: A soft introduction to object oriented programming.

Found this Rails forum today that may be of interest.
Reply With Quote
  #28 (permalink)  
Old 07-11-2007, 10:45 AM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default Re: A soft introduction to object oriented programming.

Important update on different new technologies related to Web 2.0 technologies. OO is heavily used in the libxml library, that may save you hours of work. There is no need to reinwent the wheel.

I think these posts are important:If you want to discuss XML related problems (in connection with PHP or not), I think the Sitepoint XML forum is the right place to ask / search for information. Note that Jason Sweat, the aouthor of the book php | architect - The PHP Magazine for PHP Professionals is a on the XML team.

XML and Web Services - SitePoint Forums

Copy at the DavidCastle forum.

Last edited by kgun; 07-11-2007 at 10:57 AM.
Reply With Quote
  #29 (permalink)  
Old 12-01-2007, 09:49 AM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default Re: A soft introduction to object oriented programming.

If you have read or skimmed so long I will advice you to go back to the first post of this thread. There is a new exellent book from SitePoint, by Kevin Yank & Cameron Adams (my edition September 2007) that I will draw your attention to:
If you want to learn OOP it may be natural to start with the tutorials from W3 Schools that i pointed you to in the first post and continue with this great book.

Some important topics of the book:
  1. Explains the this key word in greater detail, especially how it is used in different browsers.
  2. Describes how you can modify a pages content using DOM scripting and indicates an alternative way using the nonstandard way, the InnerHTML property.
  3. How to write accessible Java Script that may be implemented for surfters using screen readers and the key board.
  4. Comes with a Core JavaScript library that can be used and reused directly on your own sites.
  5. A complete chapter on Ajax.
  6. Looking at potential future evolutions of JavaScript.
Conclusion: One of the better computer books I have read.
Reply With Quote
  #30 (permalink)  
Old 03-04-2008, 07:48 AM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default Re: A soft introduction to object oriented programming.

This thread started with JavaScript, and as stated in the introduction, you can use the W3 Schools online JavaScript editor.

In the console tab of Firebug - Web Development Evolved firebug you can to the same. FireBug is an exellent tool to learn JavaScript and look at code (of other sites). If, as an example, you want to implement Google Maps:

Google Map

on your site. Find a site that has it implemented and see how it is done in FireBug. In the FireBug world, that is no different from looking at the source code of a page.

FireBug can also be used like an advanced validator. How to use FireBug is explained in the first book mentioned in this The desktop is on the Web. thread.

Chapter 5 "Metaprogramming with JavaScript" is higly recommended reading. It explains how you can make JavaScript more object oriented with a lot of advanced features.
Reply With Quote
  #31 (permalink)  
Old 04-17-2008, 11:39 AM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default Re: A soft introduction to object oriented programming.

If you are interested in C++ and object oriented this Interview with C++ Creator Bjarne Stroustrup
may be of interest to you.

"Then, more than three years ago (after I had moved to Texas A&M University to become a professor ...

This thread is soon seen by 10 000 visitors without being a sticky.

Last edited by kgun; 04-17-2008 at 11:42 AM.
Reply With Quote
  #32 (permalink)  
Old 05-18-2008, 12:37 PM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default Re: A soft introduction to object oriented programming.

A few weeks ago I found this

The Mjølner System: Online Information

authoritatve link on BETA and related resources that may be of interest to some members / surfers.

And don't forget this:

Some of these papers are frequently referred to but seldom read, I suspect, since they have not been easily available.

IMO referred and cited too seldom and found too deep on the SERP's when you search for

object oriented programming

in may 2008.

Sometimes I get the impression that the SE's is a search tool for Wikipedia.

Last edited by kgun; 05-18-2008 at 12:57 PM.
Reply With Quote
  #33 (permalink)  
Old 01-12-2009, 10:04 PM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default Re: A soft introduction to object oriented programming.

Some updates: php or asp.net as a career ?
Reply With Quote
  #34 (permalink)  
Old 01-13-2009, 03:13 AM
sushil's Avatar
WebProWorld Pro
 
Join Date: Apr 2008
Posts: 118
sushil RepRank 1
Default Re: A soft introduction to object oriented programming.

Nice note can you tell me the examples of object oriented languages .
Reply With Quote
  #35 (permalink)  
Old 01-13-2009, 12:54 PM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default Re: A soft introduction to object oriented programming.

Fast answer:

If you look well enough by clicking the last link in my singnature you should find a list.
Reply With Quote
  #36 (permalink)  
Old 02-11-2009, 06:19 PM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,673
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default Re: A soft introduction to object oriented programming.

A new thread of interest:

LAMP or .NET

This thread is now no #1 on google for:

a soft introduction to object oriented programming
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 10:25 AM.



Search Engine Optimization by vBSEO 3.3.0