[Qt-interest] OT: What is a "value class"
Eric Clark
eclark at ara.com
Thu Nov 19 23:44:00 CET 2009
When the term is used with the database class, it basically means that each copy of the class refers to the same connection. I, personally, think that this is a misuse or unclear way of using the term "value class." The class is not passed around as a pointer or reference, but instead a copy, which is the reason (I think) for the use of the term "value class." Every value (or instance) of the class for the same connection refers to the same connection and can be copied and passed all over the place without any loss of data. And any changes made to any of the copies will affect the original connection.
I think this can be very confusing for C++ developers especially because the use of "value" and "reference" when passing parameters is the complete opposite of what they mean here. "Pass by value" means you are making a copy and passing the copy into the function; therefore, any modification to the object in the function will not affect the original object. Whereas, "pass by reference" means that the object passed in IS the original object and any changes made inside the function WILL affect the original object.
The same terms in the case, but completely different and opposing meanings.
Does that help Any?
Thanks,
Eric
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of KC Jones
> Sent: Thursday, November 19, 2009 4:30 PM
> To: Qt-interest
> Subject: [Qt-interest] OT: What is a "value class"
>
> Sorry to be taking up so much bandwidth on this list today, but I am
> very interested in the term "value class" found in the QSqlDatabase
> documentation:
>
> "QSqlDatabase is a value class. Changes made to a database connection
> via one instance of QSqlDatabase will affect other instances of
> QSqlDatabase that represent the same connection."
>
> Googling this term is hard because it collides with use of the term in
> C# and elsewhere. So I'm hoping someone can provide a link to a good
> explanation of the term / pattern. It *sounds* like a singleton-like
> pattern that is both easy to use and easier to make thread safe. It
> also sounds like it applies to a table modeling class I've built for
> my app, the design of which I'm having to defend/explain to my peers.
> Any info about this term would be most appreciated.
>
> KC
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list