Re: What design patterns do you usually use?

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

 



2008. 02. 29, péntek keltezéssel 10.12-kor tedd ezt írta:
> 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');
> 

sure, all information belonging to an object is usually in a record of a
db.
but, you mean include('user_functions.php') automatically loads that
data? based on what? a global $user_id variable? if so, I would consider
that poor design...

> 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.

hmm that means you use only one user's info in the script. that's very
limiting.

> 
> 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.

sure you can duplicate with procedural code anything my tons of classes
do... but above a certain project size it can easily become a
maintenance nightmare and an integration nightmare if there are more
than one developers. classes enforce some strict rules to everyone in
the team, so teamwork is much more efficient and the resulting codebase
is cleaner. I know from experience, as this project with the 400K lines
is a rewrite of the previous procedural version, which was developed and
maintained by a dozen of developers over the years, and it became such a
mess that none of us wants to touch it anymore...

greets,
Zoltán Németh

> 
> 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