Object oriented programming in PHP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Object oriented programming in PHP

    Hi guys,I was trying to figure out the advantages of OOP in php,but still not getting a good reason to make it use in real work.

    Wat I'm trying to say is,

    PHP Code:
    class introduceYourself

    {
    private 
    $_name;

    public function 
    __construct($name)
    {
    $this->_name $name;
    }
    public function 
    writeName()
    {
    echo 
    'My name is '$this->_name, .'<br />';
    }
    }

    $intro = new introduceYourself("someone");
    $intro->writeName();
    ///////////////////////////////////
    output://////////////////////////
    My name is someone///////////
    ///////////////////////////////// 
    Can someone demonstrate a superb example where,use of classes will really make sense:?
    Last edited by softwarefreak; 20.12.11, 01:19.
    I need some facebook likes, can you please help me
    http://facebook.com/softwarefreakin
    I noticed social media is really powerful
    Well DONE is better than well SAID

    #2
    i think it shoulb be like this
    PHP Code:
    $i = new introduceYourself("someone");$intro $i->writeName(); 
    there are several advantages in oop,
    you can use functions with similar names in different classes,
    also you dont need to define varibles every time to the functions in classes.
    eg. if private $_name; is set, you can request its value in every function simply by using $this->_name;
    Advertise your mobile site for FREE with AdTwirl

    Comment


      #3
      you can use functions with similar names in different classes,
      also you dont need to define varibles every time to the functions in classes.
      Thanks,2 advantages making sense
      I need some facebook likes, can you please help me
      http://facebook.com/softwarefreakin
      I noticed social media is really powerful
      Well DONE is better than well SAID

      Comment


        #4
        This may help u
        DevZone

        Comment


          #5
          Im writting a varry basic understanding of oop
          PHP Code:
          class Car{
          var 
          $wheels 4;
          var 
          $doors 4;

          function 
          wheelsdoors()
          {
          return 
          $this->wheels $this->doors;
          }

          }

          $car=new car();

          echo 
          $car->wheels."<br/>";
          echo 
          $car->doors."<br/>";
          echo 
          $car->wheelsdoors() ."<br/>"
          PHP Code:
          /* I don't know everything hehe */ 
          Find me on facebook

          Comment


            #6
            OOP has serveral advantage over POP. To mention few
            1. The system you are developing reflects real world model and so it will be quite easy to implement (However pain in 4$$ if you dont understand OOP concepts and cant visualize the system)
            2. This code is modular and so modification and maintaining code becomes easy.
            3. You can re use the code, to achieve maximum re usability and so it reduce redundant code and so less efforts required.

            Some more i can say is security, abstraction, and lot more.

            All this I mentioned is just little part of advantage of whole OOP paradigm, advantages are much more.

            Added after 10 minutes:

            The concept you have currently in your mind is not pecfectly true. In OOP, we map real world entities (objects) into class. Class will also reflect the attributes that real world object has and what operation it can do (functions).
            If we take a simple example of Car (as Ponick used), to make it follow good style of OOP, we may make following classs,

            PHP Code:
            class Car {
            private 
            $name$model$manufacturer$class$year;
            public function 
            start()
            {
            }
            public function 
            accelerate() 
            {
            }
            public function 
            brake()
            {
            }
            public function 
            stop()
            {
            }

            Thus it will reflect real operations and attributes. It will have accessor method( get methods ) & mutator methods (set methods).
            I hope, this example gave you an basic idea about OOP paradigm
            Last edited by ksg91; 21.12.11, 06:53. Reason: used PHP tag instead of CODE
            Follow me @ksg91 | My Blog: http://ksg91.com | Nokia Blog: http://NokiaTips.in

            Comment


              #7
              Bunch of thanks for this help guys...
              Last edited by softwarefreak; 22.12.11, 17:34.
              I need some facebook likes, can you please help me
              http://facebook.com/softwarefreakin
              I noticed social media is really powerful
              Well DONE is better than well SAID

              Comment

              Working...
              X