![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2006
Location: MN
Posts: 7
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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. |
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Sep 2004
Posts: 207
Rep Power: 5
![]() |
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 |
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Jan 2006
Location: MN
Posts: 7
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#7 |
|
Programmer
|
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] |
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|