Faking inheritance in VBA to remove code duplication

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Jorgensen

    #16
    Re: Faking inheritance in VBA to remove code duplication

    On Sat, 10 Apr 2004 14:27:45 GMT, "rkc" <rkc@yabba.dabb a.do.rochester. rr.bomb>
    wrote:
    [color=blue]
    >
    >"Steve Jorgensen" <nospam@nospam. nospam> wrote in message
    >news:fo5f701t2 qqc0fo2bif15i5t tgb1dtb1ti@4ax. com...[color=green]
    >> On Sat, 10 Apr 2004 02:52:55 GMT, "rkc"[/color]
    ><rkc@yabba.dab ba.do.rochester .rr.bomb>[color=green]
    >> wrote:
    >>[color=darkred]
    >> >
    >> >"Steve Jorgensen" <nospam@nospam. nospam> wrote in message
    >> >news:3aid7097p ulfbnim70lt41oh mr0to1ph38@4ax. com...[/color][/color]
    >[color=green]
    >> In my case, the PreInitialize function makes it look a little like a[/color]
    >Template[color=green]
    >> Function pattern, and the meta-data looks a little bit like an Entity[/color]
    >pattern,[color=green]
    >> but an Entity would not usually do much more than validation and parsing.[/color]
    >
    >I'm leaning towards it looking somewhat like a Visitor pattern at the
    >moment.
    >
    >Whadda'ya think?[/color]

    Hmm, I think a Visitor as something that's used to perform a specific
    operation on a collection, not something that's permanently embedded in
    another object to specify some details of its behavior. For instance, I have
    a function that compares 2 collections, and it has an optional parameter of
    type IComparator that has a method called .IsEqual(var1 As Variant, var2 As
    Variant). That way, you can pass an object to the function that compares the
    collections to tell it what Equal means for the items in the collection to be
    compared.

    Comment

    • David W. Fenton

      #17
      Re: Faking inheritance in VBA to remove code duplication

      Steve Jorgensen <nospam@nospam. nospam> wrote in
      news:o8le709r4s eko9o60v7330809 el24581im@4ax.c om:
      [color=blue]
      > On Fri, 09 Apr 2004 19:25:15 GMT, "David W. Fenton"
      ><dXXXfenton@bw ay.net.invalid> wrote:
      >[color=green]
      >>Steve Jorgensen <nospam@nospam. nospam> wrote in
      >>news:3aid7097 pulfbnim70lt41o hmr0to1ph38@4ax .com:
      >>[color=darkred]
      >>> I guess I'm still not sure what pattern I'm describing, but I do
      >>> think it's a very useful pattern in VBA and solves some problems
      >>> one would normally think of using inheritance to solve in a true
      >>> OOP language.[/color]
      >>
      >>I simply can't separate the abstract part of your example from the
      >>specific type of object you're encapsulating.[/color]
      >
      > Basically, the abstract part is the part that's doing the DAO
      > calls and providing the SQL string templates since these to not
      > differ for any cases I have yet needed to employ.[/color]

      The part where I get lost is where you refer to a class that has a
      hard-wired SQL string in it as abstract. In my world, that's as
      concrete as you get.

      You're using "abstract," it seems to me, for the part of your code
      that is shared by all the classes, in this case, your setup class.
      Calling it abstract is so counterintuitiv e to me as to hopelessly
      confuse my thinking on the whole thing that I can't get any further.

      I can't say that I have a clue what you're trying to accomplish.

      At least, I can't reconcile the code you've posted with what I
      understand to be your goals.

      --
      David W. Fenton http://www.bway.net/~dfenton
      dfenton at bway dot net http://www.bway.net/~dfassoc

      Comment

      • Steve Jorgensen

        #18
        Re: Faking inheritance in VBA to remove code duplication

        On Sat, 10 Apr 2004 20:16:07 GMT, "David W. Fenton"
        <dXXXfenton@bwa y.net.invalid> wrote:
        [color=blue]
        >Steve Jorgensen <nospam@nospam. nospam> wrote in
        >news:o8le709r4 seko9o60v733080 9el24581im@4ax. com:
        >[color=green]
        >> On Fri, 09 Apr 2004 19:25:15 GMT, "David W. Fenton"
        >><dXXXfenton@b way.net.invalid > wrote:
        >>[color=darkred]
        >>>Steve Jorgensen <nospam@nospam. nospam> wrote in
        >>>news:3aid709 7pulfbnim70lt41 ohmr0to1ph38@4a x.com:
        >>>
        >>>> I guess I'm still not sure what pattern I'm describing, but I do
        >>>> think it's a very useful pattern in VBA and solves some problems
        >>>> one would normally think of using inheritance to solve in a true
        >>>> OOP language.
        >>>
        >>>I simply can't separate the abstract part of your example from the
        >>>specific type of object you're encapsulating.[/color]
        >>
        >> Basically, the abstract part is the part that's doing the DAO
        >> calls and providing the SQL string templates since these to not
        >> differ for any cases I have yet needed to employ.[/color]
        >
        >The part where I get lost is where you refer to a class that has a
        >hard-wired SQL string in it as abstract. In my world, that's as
        >concrete as you get.
        >
        >You're using "abstract," it seems to me, for the part of your code
        >that is shared by all the classes, in this case, your setup class.
        >Calling it abstract is so counterintuitiv e to me as to hopelessly
        >confuse my thinking on the whole thing that I can't get any further.[/color]

        Fair enough - read my reply to RKC on that same point to see where I was
        coming from when I used that term.
        [color=blue]
        >I can't say that I have a clue what you're trying to accomplish.
        >
        >
        >At least, I can't reconcile the code you've posted with what I
        >understand to be your goals.[/color]

        To me, that means I've probably failed to communicate well. Take another
        looking at the last code example update, ignore my misuses of terms, and see
        if that makes the intention more clear. My primary goal is to minimize
        duplication, regardless of how badly I've mangled anything else about my
        explanation.

        I'll take another stab at it this today or tomorrow, and see if I can describe
        what I'm doing in decipherable language.

        Comment

        • rkc

          #19
          Re: Faking inheritance in VBA to remove code duplication


          "Steve Jorgensen" <nospam@nospam. nospam> wrote in message
          news:eihg709ist vurlaev2l1jpddl 7jf68ur6b@4ax.c om...[color=blue]
          > On Sat, 10 Apr 2004 14:27:45 GMT, "rkc"[/color]
          <rkc@yabba.dabb a.do.rochester. rr.bomb>[color=blue]
          > wrote:
          >[color=green]
          > >
          > >"Steve Jorgensen" <nospam@nospam. nospam> wrote in message
          > >news:fo5f701t2 qqc0fo2bif15i5t tgb1dtb1ti@4ax. com...[color=darkred]
          > >> On Sat, 10 Apr 2004 02:52:55 GMT, "rkc"[/color]
          > ><rkc@yabba.dab ba.do.rochester .rr.bomb>[color=darkred]
          > >> wrote:[/color][/color][/color]
          [color=blue][color=green]
          > >I'm leaning towards it looking somewhat like a Visitor pattern at the
          > >moment.
          > >
          > >Whadda'ya think?[/color]
          >
          > Hmm, I think a Visitor as something that's used to perform a specific
          > operation on a collection, not something that's permanently embedded in
          > another object to specify some details of its behavior. For instance, I[/color]
          have[color=blue]
          > a function that compares 2 collections, and it has an optional parameter[/color]
          of[color=blue]
          > type IComparator that has a method called .IsEqual(var1 As Variant, var2[/color]
          As[color=blue]
          > Variant). That way, you can pass an object to the function that compares[/color]
          the[color=blue]
          > collections to tell it what Equal means for the items in the collection to[/color]
          be[color=blue]
          > compared.[/color]

          A Visitor is a object specifically created to provide a function for another
          specific object that the object doesn't provide for itself. A Visitor has
          to
          know enough about the object it visits to do it's job and the visited object
          must know enough to accept the visitor. The fact that you can visit a
          collection of objects is just a use of the visitor pattern not part of the
          pattern. That's my take. I may be full...

          Any who.. I guess I was sorta reaching for that one. I think I'll drop back
          to seeing it as a standard use of containment. Maybe you can name it the
          Jorgentainment Pattern.







          Comment

          • Steve Jorgensen

            #20
            Re: Faking inheritance in VBA to remove code duplication

            On Sun, 11 Apr 2004 03:41:45 GMT, "rkc" <rkc@yabba.dabb a.do.rochester. rr.bomb>
            wrote:
            [color=blue]
            >
            >"Steve Jorgensen" <nospam@nospam. nospam> wrote in message
            >news:eihg709is tvurlaev2l1jpdd l7jf68ur6b@4ax. com...[color=green]
            >> On Sat, 10 Apr 2004 14:27:45 GMT, "rkc"[/color]
            ><rkc@yabba.dab ba.do.rochester .rr.bomb>[color=green]
            >> wrote:
            >>[color=darkred]
            >> >
            >> >"Steve Jorgensen" <nospam@nospam. nospam> wrote in message
            >> >news:fo5f701t2 qqc0fo2bif15i5t tgb1dtb1ti@4ax. com...
            >> >> On Sat, 10 Apr 2004 02:52:55 GMT, "rkc"
            >> ><rkc@yabba.dab ba.do.rochester .rr.bomb>
            >> >> wrote:[/color][/color]
            >[color=green][color=darkred]
            >> >I'm leaning towards it looking somewhat like a Visitor pattern at the
            >> >moment.
            >> >
            >> >Whadda'ya think?[/color]
            >>
            >> Hmm, I think a Visitor as something that's used to perform a specific
            >> operation on a collection, not something that's permanently embedded in
            >> another object to specify some details of its behavior. For instance, I[/color]
            >have[color=green]
            >> a function that compares 2 collections, and it has an optional parameter[/color]
            >of[color=green]
            >> type IComparator that has a method called .IsEqual(var1 As Variant, var2[/color]
            >As[color=green]
            >> Variant). That way, you can pass an object to the function that compares[/color]
            >the[color=green]
            >> collections to tell it what Equal means for the items in the collection to[/color]
            >be[color=green]
            >> compared.[/color]
            >
            >A Visitor is a object specifically created to provide a function for another
            >specific object that the object doesn't provide for itself. A Visitor has
            >to
            >know enough about the object it visits to do it's job and the visited object
            >must know enough to accept the visitor. The fact that you can visit a
            >collection of objects is just a use of the visitor pattern not part of the
            >pattern. That's my take. I may be full...[/color]

            The examples I can find of visitors seem to deal with operations (such as
            compare) applied to 2 or more other object instances. I suppose the examples
            could be overly specific.
            [color=blue]
            >Any who.. I guess I was sorta reaching for that one. I think I'll drop back
            >to seeing it as a standard use of containment. Maybe you can name it the
            >Jorgentainme nt Pattern.[/color]

            I did some more research, and the closest thing I can find to the pattern I
            actually used seems to be the Template method pattern, but mine really does
            seem to be a unique variation on that pattern that can work without
            inheritance. I might not be the first to come up with it, but the only other
            documentation I can identify on VB/VBA specific patterns is in a book I don't
            yet have, and not freely available on-line.

            If inheritance was available/used, the external code would not have to
            instantiate the "Concrete" class, and that class would inherit from the
            "Abstract" class rather than being encapsulated within it. Also, in the
            Template Method pattern, one or more methods in the Concrete class might be
            accessible to the external code via inheritance of virtual public methods in
            the "Abstract" class without the need for any code in the Abstract class,
            whereas in my variation, the external code either needs to access such methods
            directly from the "Concrete" class or via wrapper functions added to the
            "Abstract" class.

            Comment

            • rkc

              #21
              Re: Faking inheritance in VBA to remove code duplication


              "Steve Jorgensen" <nospam@nospam. nospam> wrote in message
              news:i67i70de93 vd7r3vjcjsm175m lumolu6nj@4ax.c om...[color=blue]
              >
              > The examples I can find of visitors seem to deal with operations (such as
              > compare) applied to 2 or more other object instances. I suppose the[/color]
              examples[color=blue]
              > could be overly specific.[/color]

              At the risk of boring you to death (but hey, you started this) take a look
              at
              this (C# implementation)




              Comment

              Working...