Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 27th, 2006, 11:59 PM   #1
Plate
Newbie
 
Join Date: Jan 2006
Location: MN
Posts: 7
Rep Power: 0 Plate is on a distinguished road
Server side class use

How big of a role do classes play in back-end web scripting? I'm trying to figure out why I would want to take processing time to load data into objects from a database on every server request instead of keeping track of an object's state within database fields. Sure there is the ability to use session objects to remove the burden of constantly loading data into objects but that seems to be an impossible memory burden for a large user base.

On a different note:
I've been using classes as interfaces to database tables. For instance if I have a database table "clients" I then store any function that queries the client table within the class. From an organizational standpoint it works well for me because it leaves a single point for the dataflow in and out of that table. When I see class method call in the code it also gives me a clear idea of where that function is located and what table it is associated with. I'm not sure if this is a correct way to organize code or use classes. I'm not using a new object for each client just as a gateway to the client table. I've used single files for dumping common functions into for web projects but usually that file gets very large pretty fast(which is mainly just an annoyance) and when I'm looking at code with multiple includes I sometimes am not sure where a function is that is being called. I want to organize my code professionally, using the most common web programming methodologies but I think I need some advice.

Any thoughts? advice? Forum theads? links? Thanks
Plate is offline   Reply With Quote
Old Jan 28th, 2006, 8:45 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
As big a role as you like. You can code procedurally and pass random stuff to every function under the sun, decide that everything is an object and you're going to follow some obscure mantra, or anything in between. PHP's like C++ in that regard - do what you're most comfortable with. I personally like classes, but in the end it's up to you.

The same goes for your next question. There are a bazillion and a half different ways of coding professionally. If you can understand and document your code with ease, you're probably doing better than half the pros out there.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jan 28th, 2006, 8:47 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
If you can document it so that others understand it, kick that up to 80%.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jan 28th, 2006, 12:48 PM   #4
BlazingWolf
Hobbyist Programmer
 
Join Date: Sep 2004
Posts: 207
Rep Power: 5 BlazingWolf is on a distinguished road
Like Ooble said do whatever your feel comfortable with.

I personally straddle theline with classes in PHP. Sometimes I feel they are useful sometimes they seem like overkill.
__________________
_______________________________
BlazingWolf
BlazingWolf is offline   Reply With Quote
Old Jan 28th, 2006, 1:02 PM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
The purpose of a class is primarily to make an encapsulated object, like a CD player or a carburetor. Often, that's the best way to go - you can use different instantiations of the object for different purposes. I mean, you don't want to haul your car around on your back when you jog just because it's the only CD player you have available. Other times, you don't need an object, you need a procedural approach. That's like shoveling snow from your sidewalk. You may use objects in that task, but the overall task is not an object, it's a procedure. Deciding what you need and how to implement it is part of the design, best undertaken before you sit down at the keyboard.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jan 29th, 2006, 10:39 PM   #6
Plate
Newbie
 
Join Date: Jan 2006
Location: MN
Posts: 7
Rep Power: 0 Plate is on a distinguished road
It sounds like program design can be in somewhat flexible, I imagine it would be less flexible the more corporate you are.

With the onset of more "class" support in PHP I'm looking for reasons to use them and, when I do, it seems outside the realm of utilizing multiple instantiated objects. Even when the problem suggests an object I shy away from it because of the client/server model of web programming. Maybe I should just embrace procedure programming more and PHP class hype less. Thanks.
Plate is offline   Reply With Quote
Old Jan 30th, 2006, 3:49 AM   #7
KyrinComaBlack
Programmer
 
KyrinComaBlack's Avatar
 
Join Date: Dec 2005
Location: Toronto, Ontario, Canada
Posts: 48
Rep Power: 0 KyrinComaBlack is on a distinguished road
Send a message via MSN to KyrinComaBlack
I use classes alot its complicated at first then once you do it over and over again it gets easy. There is times when classes can be used and sometimes when really not need to be used. So I use classes alot but still need to understand a few more on it. I wish PHP would use multiple instance i think thats the word like

[php]
class Myclass extends Herclass extends Hisclass{

............

}
[/php]
KyrinComaBlack is offline   Reply With Quote
Old Jan 30th, 2006, 7:07 AM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I believe you mean mulitple inheritance. An instance is one object of a given class. Make a second object, you have a second instance.

Think of your design as you would any mechanical design or woodworking design. Cabinets may have drawers and doors. Drawers are objects. Drawers have knobs or handles. So do doors. On a given cabinet you probably instantiate the same knob everywhere you use it, door or drawer. You may instantiate the exact same drawer 3 times. You may also instantiate it with a greater depth. This is why I say that object-oriented design was not invented by software gurus and high priests.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:10 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC