View Full Version : Scope dilemma.

23rd June 2011, 09:31

I have a dilemma when creating cross-platform library for Qt.
Library combines pieces of code from different OS (eg, Windows, Linux).

The implementation and structure of classes in a library made in the "Qt Pimpl" style.

BUT! This style can also be implemented in two variants:

1. This is a "simple", without hiding the scope of the platform-dependent data types and constants
(eg, HANDLE, termious, etc.).
An example of this approach is Qt: QSettings.
2. This is a "complex", with hiding the scope of a private helper class such as "engine".
An example of this in Qt are: QFile, QAbstractSocket.

I attached the enclosure to test projects (currently only for Windows)
"scope_bad" and "scope_ok" which showcased two of these approaches:

scope_bad - no hidden type HANDLE in the base class implementation.
scope_ok - with a hidden type HANDLE in the base class implementation.

Please Voice your opinion on the feasibility of these two approaches.

PS: I'm more inclined to approach through the hide of scope.

Santosh Reddy
24th June 2011, 00:53
Method 1: This is adding a layer of abstraction, and gives a consistent interface to the application, which in sufficient for a simple library, you can go with it if you don't need abstraction internal to library.

Method 2: This adds more than one layers of abstraction, and still gives the same consistent interface to application (as in Method 1), this will be useful if your library is complex and has a possibility to reuse OS abstractions internally, i.e if you have some other classes in the library, which re-use BaseEngine.

I have quickly drawn something, conclusion is that if BaseEngine, is something which has a possibility to be re-used internal to library then go with Method 2, else I would be simple and go with Method 1. It some cases if BaseEngine is not re-usable as is, then it might be possible to fine grain BaseEngine, and separate the reusable parts of it, and still go with Method 2. Basically it is something how you design the framework internal to the library...


24th June 2011, 05:24
Thank you.
I consulted with our team and we have chosen a method â„–1 as the most optimal for this particular problem.