Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Design and Architecture
  4. Inherit without exposing?

Inherit without exposing?

Scheduled Pinned Locked Moved Design and Architecture
csharpoopquestion
9 Posts 4 Posters 16 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    francoisdotnet
    wrote on last edited by
    #1

    Hi Maybe I need to dig up my old varsity handbooks "Coding 101" but posting is easier :-O I want to inherit an class-A (cause I want to use it's methods in a class-B), but I don't want it's methods exposed past class-B. I.e. Dim o as ClassB, if I type "o." it should only list class-B methods. Is there a way to do this, maybe it is not called inheritance? (PS: Using VB.NET 2.0) Francois Happy Coding!

    C L 2 Replies Last reply
    0
    • F francoisdotnet

      Hi Maybe I need to dig up my old varsity handbooks "Coding 101" but posting is easier :-O I want to inherit an class-A (cause I want to use it's methods in a class-B), but I don't want it's methods exposed past class-B. I.e. Dim o as ClassB, if I type "o." it should only list class-B methods. Is there a way to do this, maybe it is not called inheritance? (PS: Using VB.NET 2.0) Francois Happy Coding!

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      instead of inehritance, you can use delegation (or aggregation), i.e. Class B will contain a reference to an instance of a class A object and delegate it to do the requested work. This way B will expos no A methods. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      F 1 Reply Last reply
      0
      • C CPallini

        instead of inehritance, you can use delegation (or aggregation), i.e. Class B will contain a reference to an instance of a class A object and delegate it to do the requested work. This way B will expos no A methods. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        F Offline
        F Offline
        francoisdotnet
        wrote on last edited by
        #3

        If I understand you correctly you're saying "Dim o as new class-A" and then use "o.methodA" in class-B. I did think of this - but was wondering if there was another ("cleaner") way to skin the cat? :confused:

        C 1 Reply Last reply
        0
        • F francoisdotnet

          If I understand you correctly you're saying "Dim o as new class-A" and then use "o.methodA" in class-B. I did think of this - but was wondering if there was another ("cleaner") way to skin the cat? :confused:

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          This is clean. Object aggregation it's often a good design alternative to complex class hierachies. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

          1 Reply Last reply
          0
          • F francoisdotnet

            Hi Maybe I need to dig up my old varsity handbooks "Coding 101" but posting is easier :-O I want to inherit an class-A (cause I want to use it's methods in a class-B), but I don't want it's methods exposed past class-B. I.e. Dim o as ClassB, if I type "o." it should only list class-B methods. Is there a way to do this, maybe it is not called inheritance? (PS: Using VB.NET 2.0) Francois Happy Coding!

            L Offline
            L Offline
            led mike
            wrote on last edited by
            #5

            You only use inheritance if B "is a" A. Not if B "has a" A. Inheritance is also sometimes called generalization, because the is-a relationships represent a hierarchy between classes of objects. Source[^]

            led mike

            S 1 Reply Last reply
            0
            • L led mike

              You only use inheritance if B "is a" A. Not if B "has a" A. Inheritance is also sometimes called generalization, because the is-a relationships represent a hierarchy between classes of objects. Source[^]

              led mike

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              Then what about private inheritance in C++? This does exactly what the OP is after.

              Steve

              L 1 Reply Last reply
              0
              • S Stephen Hewitt

                Then what about private inheritance in C++? This does exactly what the OP is after.

                Steve

                L Offline
                L Offline
                led mike
                wrote on last edited by
                #7

                I am not sure what you are getting at. :confused:

                led mike

                S 1 Reply Last reply
                0
                • L led mike

                  I am not sure what you are getting at. :confused:

                  led mike

                  S Offline
                  S Offline
                  Stephen Hewitt
                  wrote on last edited by
                  #8

                  What I'm saying is that in C++ private inheritance doesn’t really model an is-a relationship (not to the users of the class; internally to the class it does) but is inheritance nevertheless. e.g.

                  class CMyClass : private CMyBase
                  {
                      // Stuff...
                  };

                  Steve

                  L 1 Reply Last reply
                  0
                  • S Stephen Hewitt

                    What I'm saying is that in C++ private inheritance doesn’t really model an is-a relationship (not to the users of the class; internally to the class it does) but is inheritance nevertheless. e.g.

                    class CMyClass : private CMyBase
                    {
                        // Stuff...
                    };

                    Steve

                    L Offline
                    L Offline
                    led mike
                    wrote on last edited by
                    #9

                    Sorry I have no idea what your point is. The capabilities of a specific language don't alter the principles of Object Oriented Analysis and Design.

                    led mike

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups