13 Replies - 8904 Views - Last Post: 18 June 2011 - 06:38 AM

#1 Rezert  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 71
  • Joined: 17-August 08

Real OOP Examples?

Posted 18 January 2010 - 10:11 PM

I feel like I know the OOP practices, how to use it, and why to use it, but I don't really know how to use it well. For example, I can come up with a website in OOP, but I'm never really sure that I've done it right. Do you know of any possibly large open-source PHP applications that are object-oriented? It'd be nice to check one out and get a feel for what a larger application looks like when it's fully OOP.

See, I think the problem is that I learned most of my OOP practices while I was using MVC frameworks, and now that I'm moving away from frameworks, I don't know how to structure my applications.

Any examples are appreciated.

EDIT: Just for the record, the reason I'm moving away from frameworks is because of this: There is so much "Framework A is way better than Framework B because of X, Y and Z. Oh yeah, and Framework C sucks because of X as well." which all contradict each other. The two main frameworks are CakePHP and CodeIgniter, and I can't decide because I'm lured into CakePHP by it's automagic, and then put off by how complicated it is and not understanding how the automagic is working (I should really start looking at the API.) Then, I move over to CodeIgniter but am put off by it's failure to be organized (or maybe I just suck at organization.)

This post has been edited by Rezert: 18 January 2010 - 10:24 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Real OOP Examples?

#2 Martyr2  Icon User is online

  • Programming Theoretician
  • member icon

Reputation: 4316
  • View blog
  • Posts: 12,094
  • Joined: 18-April 07

Re: Real OOP Examples?

Posted 18 January 2010 - 10:56 PM

First of all, I don't think there is a PHP project out there FULLY OOP. Now if you want examples of anything with a heavy OOP look and open source, try a CMS. Joomla or Drupal have quite a few classes with an OOP design. I have created large scale PHP applications which heavily use objects and they have solved tough problems. Keep in mind that the idea isn't just to be using practices for the heck of them, but to solve real world problems. The goal of all programming is to solve problems and do it well where it is easily extendable and maintainable. This was the original idea behind frameworks but like you have said, I too find that frameworks have begun to be really fragmented and numerous. There are too many frameworks and so many in fact that some call it YAF (Yet Another Framework).

It is good you are thinking about the design and structure, but keep in sight the idea of solving a problem. Your design and techniques will vary from problem to problem. If your problem is better solved without an OOP design, then explore that. Don't feel the need to design something with OOP if it is just going to make things more complicated. Especially on the web. The web has yet to truly leverage the power of OOP because of its request-send-forget type of disconnected structure.

:)
Was This Post Helpful? 3
  • +
  • -

#3 Rezert  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 5
  • View blog
  • Posts: 71
  • Joined: 17-August 08

Re: Real OOP Examples?

Posted 18 January 2010 - 11:24 PM

View PostMartyr2, on 18 Jan, 2010 - 09:56 PM, said:

First of all, I don't think there is a PHP project out there FULLY OOP. Now if you want examples of anything with a heavy OOP look and open source, try a CMS. Joomla or Drupal have quite a few classes with an OOP design. I have created large scale PHP applications which heavily use objects and they have solved tough problems. Keep in mind that the idea isn't just to be using practices for the heck of them, but to solve real world problems. The goal of all programming is to solve problems and do it well where it is easily extendable and maintainable. This was the original idea behind frameworks but like you have said, I too find that frameworks have begun to be really fragmented and numerous. There are too many frameworks and so many in fact that some call it YAF (Yet Another Framework).

It is good you are thinking about the design and structure, but keep in sight the idea of solving a problem. Your design and techniques will vary from problem to problem. If your problem is better solved without an OOP design, then explore that. Don't feel the need to design something with OOP if it is just going to make things more complicated. Especially on the web. The web has yet to truly leverage the power of OOP because of its request-send-forget type of disconnected structure.

:)


Awesome reply, thanks. I'll check out the Joomla and Drupal source code.
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2891
  • View blog
  • Posts: 10,025
  • Joined: 08-August 08

Re: Real OOP Examples?

Posted 19 January 2010 - 07:27 AM

I tend to look at the need for OOP to be relative to size. Since its main purpose is to better organize code, it isn't really needed for something short and simple, but I can't imagine trying to write something long and complicated without it.
Was This Post Helpful? 1
  • +
  • -

#5 Xuhybrid  Icon User is offline

  • D.I.C Head

Reputation: 30
  • View blog
  • Posts: 106
  • Joined: 20-January 10

Re: Real OOP Examples?

Posted 20 January 2010 - 02:22 AM

View PostRezert, on 18 Jan, 2010 - 09:11 PM, said:

EDIT: Just for the record, the reason I'm moving away from frameworks is because of this: There is so much "Framework A is way better than Framework B because of X, Y and Z. Oh yeah, and Framework C sucks because of X as well." which all contradict each other. The two main frameworks are CakePHP and CodeIgniter, and I can't decide because I'm lured into CakePHP by it's automagic, and then put off by how complicated it is and not understanding how the automagic is working (I should really start looking at the API.) Then, I move over to CodeIgniter but am put off by it's failure to be organized (or maybe I just suck at organization.)

I'd like to recommend Kohana. It's fast, lightweight, easy to learn and its fully extendable. I'm using v2 but there is v3 under development which has been written from scratch. I really enjoy the structure and separation of MVC which was new to me when i started using it. Long gone are the days where my html is mixed with PHP applicatiion.

I'll let you research the details yourself: http://www.kohanaphp.com/

If you are looking to build an OOP system, you should stick with the MVC framework idea. Using the Models to define common functions relating to certain databases. Controllers for generating content. And views which are linked to using your controllers. Using class ... extends ..., is a great way to add common functionality across the board.

If all this is passed through 1 core file for your template, database and configurations, then you can duplicate the simple structure and then just change the pages for new OOP projects.

This post has been edited by Xuhybrid: 20 January 2010 - 02:28 AM

Was This Post Helpful? 0
  • +
  • -

#6 ludjer  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 186
  • Joined: 31-October 08

Re: Real OOP Examples?

Posted 03 February 2010 - 12:16 PM

Frame works are good but sometimes coding everything from scratch you have way more control i think
though im still thinking about it quite alot.
i got a few custom classes that i use through all my php applications though i still have to be blown me off my shoes.
its just that im used to programing using my predefined way i think also too lazy to learn a frame work since i got my own mini framework.
just my 2 cents
Was This Post Helpful? 0
  • +
  • -

#7 clementprem  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-June 11

Re: Real OOP Examples?

Posted 12 June 2011 - 08:48 PM

hello;
im new to OOP in PHP;
ive been learning it for 2weekz,,;
my question is why do we need oop in php;
how to use it in a website (realworld examples plz);
Was This Post Helpful? 0
  • +
  • -

#8 codeprada  Icon User is offline

  • Changed Man With Different Priorities
  • member icon

Reputation: 944
  • View blog
  • Posts: 2,353
  • Joined: 15-February 11

Re: Real OOP Examples?

Posted 13 June 2011 - 06:35 AM

You implement OOP every time you initialize a variable(object) with new. For instance
$pdo = new PDO("mysql:host=hostname;dbname=database", 'username', 'password');

Right there you've have create a connection to a database using a OO design instead of using
$con = mysql_connect('hostname', 'username', 'password');
.

OOP is used to represent objects or entities in programming and group similar functions and\or variables. Another powerful feature of OOP is it makes code very easy to be re-used over and over again like PDO. Once you've created an instance of a class you're free to use whatever functions or variables it has.

This post has been edited by codeprada: 13 June 2011 - 06:35 AM

Was This Post Helpful? 1
  • +
  • -

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6036
  • View blog
  • Posts: 23,432
  • Joined: 23-August 08

Re: Real OOP Examples?

Posted 13 June 2011 - 06:48 AM

Look at something like Zend Framework.
Was This Post Helpful? 0
  • +
  • -

#10 clementprem  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-June 11

Re: Real OOP Examples?

Posted 13 June 2011 - 06:49 AM

thankz for the reply
i have to develop a website by using PHP's OOP features for my assignment.
i planned to develop a stock market anaysis website which will allow users to create new accounts, search and calculate history price and ect, How can and where can i use OOP in my project.?
Was This Post Helpful? 0
  • +
  • -

#11 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2891
  • View blog
  • Posts: 10,025
  • Joined: 08-August 08

Re: Real OOP Examples?

Posted 14 June 2011 - 06:55 AM

For starters, you might have a class called stocks, which could keep track of a stock's price over time. Then you only need to create new instances of the class for each stock no need to rewrite the class methods for each stock!
Was This Post Helpful? 1
  • +
  • -

#12 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: Real OOP Examples?

Posted 15 June 2011 - 08:06 AM

Hi,

If you were keeping a record for a stocks value each day your Stock class could have a property that is an array of objects representing each of those items sorted chronologically. That way you could iterate over the array to display a history of the stocks value(maybe implement the interator interface for this?). You could make one of the Stock methods return a string formatted to interact with the Google Chart API so you could get a graph representation of the stocks value.
Was This Post Helpful? 1
  • +
  • -

#13 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 926
  • View blog
  • Posts: 3,204
  • Joined: 19-January 10

Re: Real OOP Examples?

Posted 17 June 2011 - 03:19 PM

Take a look at this.


IMO, best example of OOP.
Was This Post Helpful? 0
  • +
  • -

#14 clementprem  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-June 11

Re: Real OOP Examples?

Posted 18 June 2011 - 06:38 AM

View Postcreativecoding, on 17 June 2011 - 03:19 PM, said:

Take a look at this.


IMO, best example of OOP.


hi
thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1