On 9/19/11 2:59 PM, "ext Wolf-Michael Bolle"
<[email protected]> wrote:

>On Monday 19 September 2011 12:39:20 ext Иван Комиссаров wrote:
>
>> > > > In the spirit of this discussion I'd like to point out that I
>>need a
>> > > > way to create QMimeType objects with all their properties set.
>>Can we
>> > > > add constructors to QMimeTypeData and QMimeType like this:
>> > >
>> > > why do you need this done in the constructor? this is, to me, really
>> > > not good API. it's one of my pet peeves.
>> > 
>> > I want this class to be immutable. Such a class needs a way to get its
>> > properties initialized. Please explain why that is in your opinion a
>>bad
>> > API.
>> 
>> Yes, QMimeType should be immutable; if user need to create type in
>>code, he
>> should use QMutableMimeType.
>> 
>> So, as long as user shouldn't use QMimeType for creation of mime types,
>>we
>> can use protected constructor that takes QMimeTypeData instead.
>
>I actually dislike the inheritance. It screams for a virtual destructor
>when 
>the API really doesn't need one.
>
>How about a QMimeTypeBuilder, instead?
>
>class QMimeTypeBuilder
>{
>public:
>    QMimeTypeBuilder();
>    void setType(...);
>    ...
>    void setMagicMarkers(...);
>    QMimeType result() const { return QMimeType(d); }
>private:
>    QExplicitlySharedDataPointer<QMimeTypeData> d;   // Same as QMimeType
>};

If QMimeType is immutable and the only place where QMimeType objects get
created is within the module (ie. users can't create QMimeType objects),
I'd simply go for one constructor that takes a QMimeTypePrivate.

class QMimeType
{
        QMimeType(QMimeTypePrivate *dd) : d(dd) { /* maybe d->ref() if it's
copyable */ }
        ...
};

and QMTPrivate in qmimetype_p.h can be a simple structure:

class QMimeTypePrivate
{
public:
        QString type;
        QString comment;
        ....
};

Cheers,
Lars

_______________________________________________
Qt5-feedback mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback

Reply via email to