Submit Your Article Forum Rules

Page 1 of 4 123 ... LastLast
Results 1 to 10 of 40

Thread: A soft introduction to object oriented programming.

  1. #1
    WebProWorld MVP kgun's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    7,999

    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.

  2. #2
    WebProWorld MVP kgun's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    7,999

  3. #3
    WebProWorld MVP kgun's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    7,999

    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.

  4. #4
    Senior Member
    Join Date
    Apr 2005
    Posts
    616
    thanks man. been trying to get my head wrapped around OOP for a while and these resouces should help.

  5. #5
    WebProWorld MVP kgun's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    7,999

    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.

  6. #6
    WebProWorld MVP kgun's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    7,999

    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.

  7. #7
    WebProWorld MVP kgun's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    7,999

    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.

  8. #8
    WebProWorld MVP kgun's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    7,999

    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.

  9. #9
    WebProWorld MVP kgun's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    7,999

    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.

  10. #10
    WebProWorld MVP kgun's Avatar
    Join Date
    May 2005
    Location
    Norway
    Posts
    7,999

    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.

Page 1 of 4 123 ... LastLast

Similar Threads

  1. Why object oriented programming is becoming important
    By kgun in forum Web Programming Discussion Forum
    Replies: 1
    Last Post: 04-21-2007, 12:06 PM
  2. Introduction to the Java.util.regex Object Model
    By WPW_Feedbot in forum Graphics & Design Discussion Forum
    Replies: 0
    Last Post: 08-18-2005, 11:37 PM
  3. Looking to swap with marketing/business oriented websites.
    By MidnightWhispers in forum Marketing Strategies Discussion Forum
    Replies: 0
    Last Post: 09-11-2004, 01:12 PM
  4. International Travel Oriented Links !!
    By greg_lary in forum Marketing Strategies Discussion Forum
    Replies: 0
    Last Post: 01-25-2004, 12:10 AM
  5. Programming sound oriented web pages
    By compumonster in forum Web Programming Discussion Forum
    Replies: 0
    Last Post: 10-30-2003, 11:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •