How would you explain Object Oriented Programming to a Retard?

Discussion in 'PHP' started by TransPersonal, Feb 1, 2010.

  1. #1
    Because that's what I am, by nature I'm more creative than mathematical so programming is tough for me most of the time. I am learning PHP right now and would like to know what OOP is.

    I have heard that if you know OOP you can pick up any language quickly.

    But so far every explanation of OOP has left me even more confused. I watched this video that explains OOP to kids:

    http://msdn.microsoft.com/en-us/beginner/cc963989.aspx

    and afterward I said to myself "holy crap I'm stupider than a 5th grader!". Can someone please explain it in the easiest way possible, so even a moron like me understands?
     
    TransPersonal, Feb 1, 2010 IP
  2. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #2
    Think of a class is a blue print. which can make "objects". Each object can have different attributes.

    Say you have a blue print of a house. Then you build 3 houses based on that blue print. 1 house is red, other is blue, and another is green.

    To create an object, you use the "new" keyword, which can have a "constructor".

    $redHouse = new House('red');
    $blueHouse = new House('blue');
    $greenHouse = new House('green');
     
    Kaizoku, Feb 1, 2010 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    If you apply oop to the big picture.

    You have a:

    $house = new House();

    with:

    $room = new Room('living');
    $house->addRoom($room);

    $room = new Room('bedroom');
    $house->addRoom($room);

    $room = new Room('bedroom');
    $house->addRoom($room);

    $room = new Room('bathroom');
    $house->addRoom($room);

    $feature = new Feature('electricity');
    $house->addFeature($feature );

    $feature = new Feature('water');
    $house->addFeature($feature );

    SO you now have a house with 3 rooms and electricity and water. Each room would have its own properties and is independent of the other rooms and the house itself.

    Each room or feature or whatever can have it's own description and properties. For example, properties of a room could be color, or dimensions, etc.. It keeps pieces of code independent and modular. You could use something like features in this case as an inherited property, so that if the house has electricity, each room also has electricity. OOP can also maintain parent-child relationships, and can handle inheritance of properties from a parent.
     
    Last edited: Feb 1, 2010
    jestep, Feb 1, 2010 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    OOP is the combination of functions and variables (or methods and properties as they're known) into objects that can be duplicated from a basic blueprint.
     
    JAY6390, Feb 1, 2010 IP
  5. TransPersonal

    TransPersonal Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks a lot for the answers guys, I will deeply reflect on what has been posted here when I have some time.
     
    TransPersonal, Feb 1, 2010 IP