Author Topic: Sharing code between dwfdefinition and pdfdefinition  (Read 1644 times)

0 Members and 1 Guest are viewing this topic.

slappy

  • Guest
Sharing code between dwfdefinition and pdfdefinition
« on: October 31, 2013, 05:41:22 PM »
This is more of a streamlining question regarding Overloading, Inheritance, and polymorphism.

I'm trying to feed a pdfdefinition and dwfdefinition through the same code.  Both derived from NOD:UnderlayDefinition.

Here is the PDF code.  I have a DWF version that exactly the same word-for-word except variable names.
Code: [Select]
Dim pdfFN As String = pdfObj.SourceFileName
    Dim pdfAFN As String
    Try
        pdfAFN = pdfObj.ActiveFileName
    Catch ex As Exception
        pdfAFN = "Error"
     End Try
     Dim pdfPath As String = Mid(pdfFN, 1, pdfFN.LastIndexOf("\") + 1)
     Dim pdfFile As String = Mid(pdfFN, pdfFN.LastIndexOf("\") + 2)
     If pdfObj.Loaded = False Then
         If pdfAFN = "Error" Then
             Dim xrefData = New XrefData(pdfFile, xrefStatus.MR)
             BatcherMainDialog.xrefProp.Add(xrefData)
         Else
             Dim xrefData = New XrefData(pdfFile, xrefstatus.UL)
             BatcherMainDialog.xrefProp.Add(xrefData)
         End If
     ElseIf pdfPath <> Mid(doc.Name, doc.Name.LastIndexOf("\") + 2) Then
         Dim xrefData = New XrefData(pdfFile, xrefstatus.CR)
         BatcherMainDialog.xrefProp.Add(xrefData)
     End If
XrefData is a class holding two strings Xref file name and attachment issue
XrefStatus is a read only class supplying error messages to various attachment issues.

I've considered overloading but I can't seem to get a clean differentiation between the two types that doesn't end up with separate code paths.

I've read various explanations and code samples for polymorphism...  but I think I'm having a brain block, cuz it's not sinking in.


Thanks for your help.

owenwengerd

  • Bull Frog
  • Posts: 451
Re: Sharing code between dwfdefinition and pdfdefinition
« Reply #1 on: October 31, 2013, 05:50:25 PM »
I think it would be helpful if you described where and how specifically your attempted solution is failing.

slappy

  • Guest
Re: Sharing code between dwfdefinition and pdfdefinition
« Reply #2 on: October 31, 2013, 06:02:20 PM »
Technically my original code is NOT failing.  I'm attempting to merge two identical processes differing only by the object type.  Possibly via convert... but to what.

I'm considering using Object type to carry them into function, but I like to use Option Explicit to force myself into clean code....  although that doesn't always help. :ugly:

owenwengerd

  • Bull Frog
  • Posts: 451
Re: Sharing code between dwfdefinition and pdfdefinition
« Reply #3 on: October 31, 2013, 06:49:54 PM »
Technically my original code is NOT failing.

Hence my suggestion. I'm sure *you* know what you're having trouble with, but the rest of us don't. Posting failing code is one way to help describe what you're having trouble with.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Sharing code between dwfdefinition and pdfdefinition
« Reply #4 on: October 31, 2013, 11:20:43 PM »
Looking at snippet of it looks you are not using any methods or properties from either of the derived classes and if that is the case you just treat it as UnderlayDefinition object.
 Looking at docs PdfDefinition does not add any members or properties and dwfDefinition only adds one property isDWFx.
 
So a function like
Public Function DoUnderlayStuff(Byval definition as UnderlayDefinition )
...........Do stuff
End Function
 
Now you just pass in a DwfDefinition or a PdfDefinition object and use one function.
 
 

slappy

  • Guest
Re: Sharing code between dwfdefinition and pdfdefinition
« Reply #5 on: November 01, 2013, 04:50:09 PM »
That's it Jeff, Thanks for lead in.

I didn't occur to me the dictionaries could be accessed without a cast.

Thanks again.