SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    Under Construction Poop_Shoot's Avatar
    Join Date
    Jul 2003
    Location
    Sacramento, CA
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What Makes It OO!

    Are you ready for my stupid question of the day? What qualifies as an OO script rather than falling into the category of procedural? Take this script for example!

    http://www.sitepointforums.com/showt...hreadid=127788 [refering to script posted by beetle!]

    What make it OO? Thanxs!

    Jon

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, a generic definition of OO is something like "Data, and the code for manipulating that data, are bound together". This is also called encapsulation.

    Since I'm creating objects using the new operator, each instance is separate from the other. So, one set of code/functions is used to create multiple instances of same process/result.

    I'd explain in more detail if I had more time. Perhaps some others will join in
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    Under Construction Poop_Shoot's Avatar
    Join Date
    Jul 2003
    Location
    Sacramento, CA
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok great that is a perfect explenation! So basically this can be helpfull to reuse code rather than writing 5 different functions to carry out basically the same operations!

  4. #4
    SitePoint Evangelist Mr. Brownstone's Avatar
    Join Date
    May 2002
    Location
    Relative
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Technical Persuit have quite a good explanation of OOP.
    Of course, that's just my opinion. I could be wrong.

  5. #5
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    5 different functions to carry out basically the same operations!
    not necessarily. You could write 1 function, pass five different number of arguments to handle 5 different types of operations and that isn't oop.

    for example:

    function getArea(shape)
    {
    var area = null;
    switch(shape)
    {
    case 1:
    area = arguments[1] * arguments[2];
    break;
    case 2:
    area = 3.14 * (arguments[1] * arguments[1])
    break;
    default:
    area = null;
    }
    }

    The above is not oop.
    but if you created an object:
    var rectangle = new Object();
    and then started giving it properties and methods:
    rectangle.len rectangle.wid rectangle.getArea()
    you are getting close to oop.

    The ideal oop allows very few entry points to its data and methods. Only those things declared public are accessible to outside functions; things declared private can be altered only by internal methods within the object itself. (Then again, there's no such thing in javascript)

    Somewhere at sitepoint there's an introductory article on oop, written by ariellaDog, which you might find useful.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


Bookmarks

Posting Permissions

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