Clean constructors
Hi everyone. I saw such line in the Qt Essentials Curriculum Block: “Understand the importance of clean constructors” (Writing your own widgets).
So, what means “clean constructor”?
10 replies
My understanding of it is to just have constructors that are simple and only take a very small number of arguments (if any).
For example it is better to have code like:
- ProgressBar* progress = new ProgressBar( this );
- progress->setRange( 0, 1000 );
- progress->setValue( 230 );
as opposed to
- ProgressBar* progress = new ProgressBar( 0, 1000, 230, this );
as you just end up with a bunch of meaningless numbers in your code. With the former you can see the numbers in the context of the member function which gives a clue as to their meaning.
I was thinking of this article [doc.qt.nokia.com] when I wrote my reply.
Unfortunately, I also don’t know the proper definition. I found this topic searching on the Internet to find it.
And as you can see at http://qt.nokia.com/developer/learning/certification/exams/preparation-prerequisites/qt-curriculum/qt-essentials clean constructors are in the Essentials block (See section “Writing your own widgets”)
You must log in to post a reply. Not a member yet? Register here!






