Nick
VIP
v5 Beta Tester[M:5000]
Philadelphia Eagles: 8-8
Posts: 2,239
|
Post by Nick on Jan 19, 2011 6:11:11 GMT
Do any of you guys do this? As it is, I usually write my web applications by just having a functions file and maybe a constants file, but I want to start coding OO. Any expirences with OO programming?
|
|
Jordan
Elite Poster
[M:5000]
Posts: 286
|
Post by Jordan on Jan 20, 2011 4:08:01 GMT
I almost always use OO unless I'm writing a very short code, and if you ever start writing large scripts or programs (meaning thousands of lines or more), you'll really want to be using it. The syntax varies from language to language, but once you get it down in one language it's easy in all the others. And just so you know, languages like Javascript and Lua are a little different because they use prototypal inheritance rather than classical inheritance (like C++, Java, php etc.) so you have to think differently about your problem. If you ever have any questions shoot me a private message.
|
|
Nick
VIP
v5 Beta Tester[M:5000]
Philadelphia Eagles: 8-8
Posts: 2,239
|
Post by Nick on Jan 20, 2011 4:45:37 GMT
Sweet. I stumbled across a script awhile back that was OO, but it took me forever to get. But then things started to click, so I have an understanding of what it is, but now I think I just need to jump in because I learn best from expirence Keep an eye on your inbox though
|
|
Jordan
Elite Poster
[M:5000]
Posts: 286
|
Post by Jordan on Jan 20, 2011 5:22:14 GMT
The best thing to do is to read a lot about it, and then start implementing your own classes. There's quite a bit to learn, but fortunately most of it is very logical and will make sense to you so it will be easy to learn.
And will do. :]
|
|
Nick
VIP
v5 Beta Tester[M:5000]
Philadelphia Eagles: 8-8
Posts: 2,239
|
Post by Nick on Jan 20, 2011 18:37:54 GMT
One question that I have been trying to find. What kinds of classes do phpbb and wordpress use? Like login or db classes. I want to get a feel on how many classes I may need to make.
|
|
Jordan
Elite Poster
[M:5000]
Posts: 286
|
Post by Jordan on Jan 20, 2011 22:50:47 GMT
The best thing to do is to download the source code. I know phpbb is open source so you can look at it all yourself. I don't work with php much because I mainly work with programming languages, but when I do I organize nearly everything into an object. Here's a great tutorial by Bobby Hensley that I think will be very useful to you. www.prowebforums.com/tutorials/article/18-secure-login/And here's a basic skeleton of a class that I wrote a long time ago when I was just messing around. The coding is outdated, but it should give you an idea of what you can do. <?php
require_once("/../../config.inc.php");
class Database { public $connection; public static $connections;
/** * Keep track of how many connections there are. */ public function __construct() { self::$connections++; $this->connect(); }
function __destruct() { self::$connections--; $this->disconnect(); }
/** * Connects to the mysql database. */
public function connect() { if(!isset($this->connection)) { // Open a mysql connection. $this->connection = mysql_connect( $GLOBALS["config"]["db"]["host"], $GLOBALS["config"]["db"]["user"], $GLOBALS["config"]["db"]["pass"] ) or die("Error: " . mysql_error());
// Connect to the database. mysql_select_db( $GLOBALS["config"]["db"]["name"], $this->connection ) or die("Error: " . mysql_error()); } }
/** * Disconnects from the mysql database. */
public function disconnect() { if(isset($this->connection)) { mysql_close($this->connection); } } }
?>
|
|
Nick
VIP
v5 Beta Tester[M:5000]
Philadelphia Eagles: 8-8
Posts: 2,239
|
Post by Nick on Jan 21, 2011 2:32:16 GMT
Thanks! I just downloaded an OO reference for my ipod and it is providing really useful!
|
|
Jordan
Elite Poster
[M:5000]
Posts: 286
|
Post by Jordan on Jan 21, 2011 5:20:43 GMT
Cool. Just be sure to read about topic like inheritance, polymorphism, encapsulation etc.
|
|
Nick
VIP
v5 Beta Tester[M:5000]
Philadelphia Eagles: 8-8
Posts: 2,239
|
Post by Nick on Jan 21, 2011 6:07:00 GMT
Alright. I am finding the phpbb wiki useful!
|
|
Jordan
Elite Poster
[M:5000]
Posts: 286
|
Post by Jordan on Jan 21, 2011 22:03:51 GMT
Wiki = win
|
|
|
Post by spartans63 on Jan 23, 2011 3:06:17 GMT
Yeah, I use OO whenever I need to encapsulate data that shares something in common. If I just need to feed data into something and take the output, I'll just use functional programming, but I usually intend to design my code around OO principles.
|
|
xcessive
Epic Poster
.[M:5000]
Posts: 526
|
Post by xcessive on Jan 23, 2011 4:32:48 GMT
Why is this in server side?
Anyways, OOP is the way to go for anything bigger than a tiny project.
|
|
Nick
VIP
v5 Beta Tester[M:5000]
Philadelphia Eagles: 8-8
Posts: 2,239
|
Post by Nick on Jan 23, 2011 5:10:15 GMT
Yeah. Im building my first oo project! Others had just been outsourced functions and constants and headers and footers. No classes
|
|
xcessive
Epic Poster
.[M:5000]
Posts: 526
|
Post by xcessive on Jan 24, 2011 0:18:28 GMT
Yeah, I use OO whenever I need to encapsulate data that shares something in common. If I just need to feed data into something and take the output, I'll just use functional programming, but I usually intend to design my code around OO principles. Use a struct.
|
|