Re: What design patterns do you usually use?

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

 



2008. 02. 28, csütörtök keltezéssel 09.12-kor tedd ezt írta:
> At 8:57 AM +0100 2/28/08, Zoltán Németh wrote:
> >2008. 02. 27, szerda keltezéssel 14.02-kor tedd ezt írta:
> >  > Just about all my code was reduced to functions
> >>  and all functions were placed in files according
> >>  theme. My "main" was probably less than 50 lines
> >>  of code.
> >
> >this is absolutely similar to a well-organized class structure, just
> >replace 'file' with 'class' :)
> 
> and
> 
> >well, if classes are not convenient for you, then sure it would take
> >more time but only for the first time. after that, my experience is that
> >development time is less with classes
> 
> A rose by any other name.
> 
> Outside of being up on the current trend, I don't 
> see much difference -- just new paint on an old 
> thing. I've seen a couple of paint jobs over the 
> years. What I haven't seen is something that I 
> can't do with what I've got.
> 
> Classes only provide me with a different way to 
> organize my code. Sure you can cite data hiding, 
> inheritance, and polymorphism, but I didn't have 
> problems that required those before -- so why 
> should I worry about them now? (however, 
> polymorphism is cool).

> Yes, it's kind of neat to make a class with it's 
> own variables and methods and set a level of 
> abstraction that permits you to not care what is 
> is used for, but I really do that with functions 
> anyway.
> 
> From my perspective, increasing complexity doesn't always make things simpler.

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

and this example does not illustrate the most powerful advantages of
oop, some of which you already mentioned above, like inheritance, access
control, interfaces, etc

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