instanceof and PdfDataObject

  • Joe Blogger

    Joe Blogger - 2009-02-15

    Stefano - I am impressed with your work so far.

    I have recompiled the library with all PdfDataObject references now PdfObject

    It seems to work well.

    Is that abstraction really needed ?

    Also have you considered any better ways of testing objects rather than using instanceof ?

    • Stefano Chizzolini

      Hi Joe

      1) PdfDataObject.
      Why do you hate PdfDataObject? ;-)
      I'm glad you're experimenting with PDF Clown, but PdfDataObject is not an arbitrary class; let me explain in the following notes.

      It's perfectly possible that you could substitute PdfObject for PdfDataObject without compilation problems: actually, PdfDataObject's interface is the same as PdfObject... but in this way you are missing the relevant point: semantics! PdfDataObject is a special PdfObject which models PDF data entities, differently from, say, PdfIndirectObject (another specialization of PdfObject) which serves as an infrastructure entity bearing PdfDataObject instances for reference purposes. If you use PdfObject in place of PdfDataObject you introduce the possibility to assign inappropriate objects (I don't think it's a wise choice...).
      If you want to understand the motivations behind the design and implementation of the library, I suggest you to skim through the User Guide included in the current downloadable release.

      2) 'instanceof'.
      I obviously know that polymorphism generally must be preferred to the 'instanceof' operator; I extensively used interface abstraction and limited 'instanceof' to particular situations. Please be more specific (show me some code fragments you judge improvable and propose your better solution), thank you.



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks