Hi zyx,
I come around to your position. AFAIK since there is no
non-static class member in each of these factory classes,
there is nothing to instantiate extra after the static
initialisation, so a "new" should be a no-op, so no abuse
of RAM occurs.
I have run with your OK to make the constructors private,
since I think in library-using code there should be no
misunderstanding about these classes' methods being static.
The updated patch is attached, I'm sorry I'm sending it only
now. I had wanted to fix cross-build issues before (please see
my second-latest e-mail, sorry for omitting that I have build-
tested that patch with shared-lib and static build for GNU/Linux
native and also both for cross-build to Win32). This patch is also
so tested. Additionally I attended a company Christmas party
on Friday (it was fun, I had interesting conversations).
Please reserve the revision numbers 1700 and 1701 for me, I'll send
something special (I hope it's OK to keep it a surprise until very
soon, maybe I'll get to it this Sunday).
Best regards, mabri
----- Original Message -----
From: zyx <z...@litepdf.cz>
To: podofo-users@lists.sourceforge.net
Sent: 7:53 Tuesday, 1 December 2015
Subject: Re: [Podofo-users] Prohibit instantiation of factories (all methods
static)
On Mon, 2015-11-30 at 23:51 +0000, Matthew Brincke wrote:
> how would you ensure that nobody abuses a static-methods-only
> factory class? What do you think of as best practice? I think,
> warning and error messages are instrumental to prevent abuse.
> Regarding the "unfinished work": should I submit an empty inline
> implementation (but commented out to prevent calls to it)?
Hi,
I hope we both agree that having something declared, but not
implemented anywhere is wrong in general. It can strike back in
different ways, like adding work to someone else extending the class
and realizing that there is missing code. I believe we can find other
good reasons too.
I would not call it 'abuse', if the caller wants to instantiate a class
which provides only static methods, then it's up to him/her. One semi-
valid reason can be to "save source code size". Instead of calling each
method as PdfEncodingFactory::some_method_to_call(), it can be called
as here:
PdfEncodingFactory ef;
ef.some_method_to_call();
Stupid example, I know, but exhibits that there is no abuse involved in
the instantiation of the class. At least from my point of view.
Nonetheless, if you want to ensure that the class will not be
instantiated, then your way of adding the constructor in the 'private'
section if completely fine. What I claimed about was the declaration
without implementation of the methods (constructors, in this case).
Declaring them with empty body is fine too.
Hope it helps.
Bye,
zyx
--
http://www.litePDF.cz i...@litepdf.cz
------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users
Index: src/base/PdfEncodingFactory.h
===================================================================
--- src/base/PdfEncodingFactory.h (revision 1693)
+++ src/base/PdfEncodingFactory.h (working copy)
@@ -181,6 +181,8 @@
static const PdfIdentityEncoding *s_pIdentityEncoding;
static Util::PdfMutex s_mutex;
+ // prohibit instantiating all-methods-static factory from outside
+ PdfEncodingFactory() {};
};
}; /* namespace PoDoFo */
Index: src/base/PdfFilter.h
===================================================================
--- src/base/PdfFilter.h (revision 1693)
+++ src/base/PdfFilter.h (working copy)
@@ -520,6 +520,8 @@
* \returns a list of filters
*/
static TVecFilters CreateFilterList( const PdfObject* pObject );
+private: // prohibit instantiation of all-methods-static factory from outside
+ PdfFilterFactory() {};
};
Index: src/doc/PdfFontFactory.h
===================================================================
--- src/doc/PdfFontFactory.h (revision 1693)
+++ src/doc/PdfFontFactory.h (working copy)
@@ -114,6 +114,8 @@
const PdfEncoding* const pEncoding,
bool bEmbed, bool bSubsetting, PdfVecObjects* pParent );
+ // prohibit instantiation of all-methods-static factory from outside
+ PdfFontFactory() {};
};
};
------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users