You are here: Re: beginner oop: class not alway working « All PHP « IT news, forums, messages
Re: beginner oop: class not alway working

Posted by Vince Morgan on 03/29/07 01:33

"Osewoudt" <oswwoudt@ufo.org> wrote in message
news:460abf73$0$30727$ba620dc5@text.nova.planet.nl...
> hello,
> ------------------------ code to show password -----------
> // make an object;
> $test = new WachtwoordGenerator();
> // choose the amount of elements from each array;
> $test -> kLetter = 8;
> $test -> hLetter = 3;
> $test -> cijfer = 2;
> $test -> leesteken = 4;
> // true means that the password contains only unique elements;
> // false means that duplicates are allowed;

It appears that the class would only ever be a single instance.
If so you should be setting the values within the constructor.
ie;
$test = new WachtwoordGenerator(8, 3, 2, 4);
Although this appears to be a test and learning project it's a good time to
create some good habits.
The class should encapsulate more functionality than this one does.
The numbers "8, 3, 2, 4" have to come from somewhere. Why not generate them
within the class itself with rand numbers.
Then you could do the following;
$test= new WachtwoordGenerator();
$password = $test->pword();
Now you only have two statements involved in generating a password.
A very big part of "oop", or "obp" is data encapsulation.
There was once a time when you had to oil bits of an internal combustion
engine every time you used it. Today every such engine I know of uses
encapsulation to do the oiling for you. You just need to keep an eye on the
oil available to the system. No, I'm not calling you a "dipstick" :)
You are oiling the engine yourself when you call "_set" on a class that is
created once for it's output then discarded.
No crticism inteded here, just a nudge toward a better understanding of the
use, and usefullness, of classes.
HTH
Vince Morgan

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация