abstract class

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

    abstract class

    Can we provide definition for not pure virtual functions (PVF) i.e.
    methods in Abstract class - given that we have at least one PVF? IF
    yes, where would it be used? can a suggestive example be provided?


    thx

  • Victor Bazarov

    #2
    Re: abstract class

    puzzlecracker wrote:[color=blue]
    > Can we provide definition for not pure virtual functions (PVF) i.e.
    > methods in Abstract class - given that we have at least one PVF? IF
    > yes, where would it be used? can a suggestive example be provided?[/color]

    Yes. Wherever the design needs it to be used. Do it yourself.

    Comment

    • chris

      #3
      Re: abstract class

      puzzlecracker wrote:[color=blue]
      > Can we provide definition for not pure virtual functions (PVF) i.e.
      > methods in Abstract class - given that we have at least one PVF? IF
      > yes, where would it be used? can a suggestive example be provided?
      >[/color]
      I'm not sure what you want (assuming this isn't just a homework
      question). You can definatly have non-pure virtual functions in a class
      with pure virtual functions. You'd want them whenever you have an
      abstract class where there exists some common overloadable functionality
      all objects of that type (and derived types) want.

      Comment

      • puzzlecracker

        #4
        Re: abstract class

        I was interested of whether it is needed, for you cannot create an
        object of an abstract class, so having the definition appears to be an
        exercise in futility.

        Actually, I see one intuitive explanation, that are objects of
        subclasses should have identical implementation of a method in the base
        class... is it a valid case, are there more cases where it is needed?
        thanks.

        Comment

        • Mike Wahler

          #5
          Re: abstract class

          "puzzlecrac ker" <ironsel2000@gm ail.com> wrote in message
          news:1105984623 .951988.136420@ c13g2000cwb.goo glegroups.com.. .[color=blue]
          > I was interested of whether it is needed, for you cannot create an
          > object of an abstract class, so having the definition appears to be an
          > exercise in futility.[/color]

          No it's not. It can provide a 'default' behavior for
          objects of derived type which don't implement it.
          [color=blue]
          > Actually, I see one intuitive explanation, that are objects of
          > subclasses should have identical implementation of a method in the base
          > class...[/color]


          :-)
          [color=blue]
          > is it a valid case,[/color]


          Sure, why not? But of course 'validity' can only be
          assessed for each particular heirarchy design.
          [color=blue]
          > are there more cases where it is needed?[/color]

          I don't think so, but I could easily be overlooking something.
          I wouldn't worry about it, just use it if it seems appropriate
          to your design. Actually it could also be used as a 'place holder'
          for code you haven't written yet, letting you have a 'complete'
          entity for testing.


          -Mike


          Comment

          • le ténébreux

            #6
            Re: abstract class

            "puzzlecrac ker" <ironsel2000@gm ail.com> wrote:
            [color=blue]
            > I was interested of whether it is needed, for you cannot create an
            > object of an abstract class, so having the definition appears to be an
            > exercise in futility.
            >
            > Actually, I see one intuitive explanation, that are objects of
            > subclasses should have identical implementation of a method in the base
            > class... is it a valid case, are there more cases where it is needed?
            > thanks.[/color]

            Even if only a large portion (not all) of your derived classes are
            going to use the same implementation, giving that definition in the
            base class will save you from having to define it for each of those.

            For example, I'm working on a set of Windows GUI wrapper classes.
            Each window class uses a completely different method for processing
            messages from the OS, so I've declared a pure virtual function in
            the base class for that. On the other hand, they almost all, with
            a few exceptions, use the same method for repositioning and resizing
            when their parent window changes, so I put that implementation into
            the base class and just override it in the few cases where it needs
            to be different.

            Comment

            Working...