Re: What design patterns do you usually use?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 8:52 AM +0100 2/29/08, Zoltán Németh wrote:
it's not just that, it's also a different way of thinking about your
data. for example say you have a 'user' - you always have one of that ;)
in procedural code you would store the properties of the user in an
array or whatever, and have an include file with functions to manipulate
the user. so why not group those two together in a class?

<very simplifying example>

procedural code:
include('user_functions.php');
$user = load_user_data($userid);
$user = set_user_name($user, 'tedd');

oop code:
include('user.class.php');
$user = new User($userid);
$user->setName('tedd');

</very simplifying example>

see, same number of lines, so no added complexity. however the second
one has some advantages:
- you don't have to pass around the data since it is grouped together
with the method you call
- you don't have to worry about some ignorant developer calling
set_user_name with, say, a product array - User->setName will always be
called on a user object
- the second one looks soo better ;) (ok, you said, new paint :) )

I can understand your oop code very well -- but your procedural code example is lacking.

First, if I were to have information tied to a user, then I would use MySQL and establish a record with all the fields I needed for that user. My code simply would be:

include('user_functions.php');
$user = set_user_name($user, 'tedd');

And thus, two lines instead of three.

But in fairness, the user_functions.php would establish a connection to the database and the function "set_user_name($user, 'tedd')" would simply use 'tedd' with respect to whatever "$user" is.

The number of lines of code really doesn't apply with respect to organization value -- after all, the best organization is to document your code which certainly adds lines of "code". Sure, one can argue that remarks are not code, but code without them would be different, so in my mind it's all code.

I don't think that you can show me an oop example that I can't duplicate procedurally and that's my point. Oop provides a different organization method.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux