PHP Developers Network
http://forums.devnetwork.net/

My Class file! Need Critique!
http://forums.devnetwork.net/viewtopic.php?f=50&t=136185
Page 1 of 1

Author:  karolismf [ Mon Jul 09, 2012 11:46 am ]
Post subject:  My Class file! Need Critique!

solved thanks. Guys.

Author:  Christopher [ Mon Jul 09, 2012 12:19 pm ]
Post subject:  Re: My Class file! Need Critique!

Lots of code there. For me the two big issues are:

1. Lack of separation between the code that generated the output and the code that contains the business/domain logic

2. Not naming you objects as specific nouns. You have a class called "Check" which is about the most generic term possible. The name does describe what the object is. Likewise you use the work "accounts" which is also general. If they are user accounts then call the table and the object "users". Your naming leads to the wrong separations.

Author:  karolismf [ Mon Jul 09, 2012 12:29 pm ]
Post subject:  Re: My Class file! Need Critique!

Hmm, for first and secound issue i understood about more than half of it. Sorry, i don't have such great english. so if i understand it right you mean that in forgotPassword i have all code about forgotPassword and there is somecode in Check? it's unnecessary using from two classes code breaking? Hmm, first of all lets fix some things in my code and post fixed. Then we will move forward. here some fixes:
....

okey now look throught it again and tell me if i solved even one of your issue? :) And thanks for help.

Author:  Christopher [ Mon Jul 09, 2012 3:36 pm ]
Post subject:  Re: My Class file! Need Critique!

This kind of discussion would be easier in your native language -- sorry about that.

My main comment is that classes are usually named using nouns and methods named using verbs. That makes class names describe what the object is and the data it contains. Using verbs makes methods describe what they do. It is even better if method names follow the "Tell Don't Ask" style if possible. Good naming comes from good decomposition of the the problem and the domain.


Microsoft
Class Naming:
Method Naming:

Wikipedia
http://en.wikipedia.org/wiki/Naming_con ... ramming%29

Author:  karolismf [ Mon Jul 09, 2012 3:53 pm ]
Post subject:  Re: My Class file! Need Critique!

"My main comment is that classes are usually named using nouns and methods named using verbs" Is it something to do with the coding or the code will have holes if i don't fix this problem, or my web security is on risk if i don't change them? :) if no, then please give me your own example how should it look like. I would compere to mine and i think it would be easier for both of us understand each other. And if yes, then i want an example for the best coded example in this situation. :) Thanks. "This kind of discussion would be easier in your native language -- sorry about that. " Np. I am not very good in english far more worse than you, sorry for bad english. :) (readed again, so you suggest to write the class names something diffrent from it's functions? like class forgotPassword/ so we name it arWt4dfWF)?

Author:  Christopher [ Mon Jul 09, 2012 5:37 pm ]
Post subject:  Re: My Class file! Need Critique!


Author:  karolismf [ Mon Jul 09, 2012 6:30 pm ]
Post subject:  Re: My Class file! Need Critique!

Hmm, well you are half right about forgotpassword.php, my site uses only index and it calls includes if there is string in url like mysite.com/?a=forgot, then it calls a file./// I created html pages for solution if success sending forgotPassword or failed. And ofcourse your new password was send html page. In my website there is only one class that uses the forgotPassword system it's in here. And ofcourse we must count the mailer class, which gets an information of forgotPassword that is filed by user and sends an email. In other words my forgotPassword at website uses two classes one is Class forgotPassword, secound Class Mailer. (My forgot password sends the $_POST['email'] to forgotPassword class - the class first of all filters the text then checks if the users filed information is valid and it isn't empty if that data is valid it checks database if the user filed information matches in database if yes, then in forgotPassword we call secound class name Mailer and call it's public function sendForgot using the information stored from user. Then the function do it's job and mail was send to your email. Then in email i got an mail from my website with a link for forgotPass reset, i use it and it opens my website which uses the include controler with link mysite.com/?something=...&... when pressed link it opens new file with stored information of "mysite.com/?something=...&..." it checks if this thing was really done.(he checks throught database) then he calls in forgotPassword again Class Mailer and this time it uses diffrent Mailer function with information stored from the link. The secound mail gives you new mail with new password.) Like again i didn't understand something in your post it was the last line. :) If you have skype it would be great to write throught it becouse this is long conversation...

Author:  Christopher [ Mon Jul 09, 2012 10:31 pm ]
Post subject:  Re: My Class file! Need Critique!


Author:  karolismf [ Tue Jul 10, 2012 5:01 am ]
Post subject:  Re: My Class file! Need Critique!

k, now i get it. But why? is it more secure or better for the website and it's function quality?

Author:  Christopher [ Tue Jul 10, 2012 9:46 am ]
Post subject:  Re: My Class file! Need Critique!


Author:  MichaelR [ Wed Jul 11, 2012 6:10 am ]
Post subject:  Re: My Class file! Need Critique!

A couple of things:

1) Use curly brackets even when they're not necessary; it's more future proof.

Syntax: [ Download ] [ Hide ]
// Bad
  public function process()
  {
    if( $this->valid_token() && $this->valid_data() )
           $this->register();

    return count( $this->errors )? 0 : 1;
  }

// Good
  public function process()
  {
    if( $this->valid_token() && $this->valid_data() )
    {
           $this->register();
    }
    return count( $this->errors )? 0 : 1;
  }


2. Switch to the MySQLi extension or PDO to make use of prepared statements. This can speed up your application and will prevent SQL injections.

Author:  karolismf [ Sat Jul 14, 2012 5:57 am ]
Post subject:  Re: My Class file! Need Critique!

Hmm, i will try. to change everything as you said. :) Anything else. And Christopher i will try to make more classes as you suggested. :)

Author:  Christopher [ Sat Jul 14, 2012 8:19 am ]
Post subject:  Re: My Class file! Need Critique!


Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/