Hi Kangil,

 

Well first of all you have to strictly follow the pattern and not to forget putting macros where they are supposed to be,

It might be confusing from the beginning. Chris and me however promise  to describe the approach in the EFL coding style wiki.

 

Another drawback is passing calls through an extra pointer because of pimpl, so performance can be affected in theory.

 

BR,

Mikhail

 

From: webkit-efl-bounces@lists.webkit.org [mailto:webkit-efl-bounces@lists.webkit.org] On Behalf Of Kangil Han
Sent: Thursday, October 18, 2012 4:58 PM
To: Dumez, Christophe; webkit-efl@lists.webkit.org
Cc: Christiansen, Kenneth R
Subject: Re: [webkit-efl] Use of pimpl idiom for Ewk classes

 

Hi Chris,

 

FOA, thanks for the interesting topic here. :)

From this, I’ve learned about useful design pattern and implementation technique with respect to encapsulation in C++.

 

I personally believe things have two aspects, e.g. pros and cons. :)

Here pros is strongly clear.

We can save the word for encapsulation.

 

Then, now my question is what’s the cons from this change?

It seems QT project widely uses this kind of technique called D-pointer.

Any report from them?

 

Kind regards,

Kangil

 

From: webkit-efl-bounces@lists.webkit.org [mailto:webkit-efl-bounces@lists.webkit.org] On Behalf Of Dumez, Christophe
Sent: Thursday, October 18, 2012 5:56 PM
To: webkit-efl@lists.webkit.org
Cc: Kenneth R Christiansen
Subject: [webkit-efl] Use of pimpl idiom for Ewk classes

 

Hi,

Mikhail and I are currently working on refactoring the Ewk classes to make them more C++-like, more convenience to use and less bug-prone.
As part of this work, we came out with a proposal: Use pimpl idom for Ewk classes.

The Ewk classes are currently defined in the private headers, with all their members public. The private headers also usually contain C-style functions to interact with the Ewk class from inside WebKit.
Now, we would like to get rid of those private C functions and replace them with C++ methods in the Ewk class. The issue is that the Ewk class members are currently public meaning we can alter the members directly from outside the Ewk class implementation and bypass those class methods.

At the same time, we don't want to make all the Ewk class members private and create getter / setter methods for all of them. Not only this means a lot of refactoring work and extra code, but also, this means that are public C API implementation will need to go through those getters / setters as well, instead of interacting with the class members directly.

We therefore thought of using the pimpl idiom so that the class members are now stored in a POD struct in the cpp file. This effectively prevents access to them from code other than our public C API and Ewk class methods, which is what we want. The C API functions can still directly interact with the Ewk class members which is convenient. We can get rid of all C functions in the private headers and replace them with Ewk class methods. Therefore, the coding style in WK2 EFL port implementation with be more C++ oriented.

I created a meta bug for this task:
https://bugs.webkit.org/show_bug.cgi?id=99696

I also wrote a first patch to show what the result looks like for the Ewk_Download_Job class. The patch also adds convenience macros to ewk_private.h to make pimpl idiom usage simpler and less error-prone:
https://bugs.webkit.org/show_bug.cgi?id=99697

We hope you like the result as much as we do.
If everyone agrees, Mikhail and I are planning to port other Ewk classes to this proposal and update the WebKit EFL coding style.

Kr,
--
Christophe Dumez
Linux Software Engineer, PhD
Intel Finland Oy - Open Source Technology Center

---------------------------------------------------------------------
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki
Business Identity Code: 0357606 - 4
Domiciled in Helsinki

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.