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. C#
  4. C# OOP Design

C# OOP Design

Scheduled Pinned Locked Moved C#
questioncsharpdesign
4 Posts 4 Posters 0 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.
  • X Offline
    X Offline
    XeoN Kc
    wrote on last edited by
    #1

    I have to design a library of classes. They are to inherit from a common base class. However I want to be able to call members of the class without making a distinction of which class it particularly is. I was thinking of an interface for the last point I mentioned. Question : Would I'll be able to make my classes inherit this interface without directly inheriting the base class (i.e. the base class is inherited by interface)??:wtf:

    G K C 3 Replies Last reply
    0
    • X XeoN Kc

      I have to design a library of classes. They are to inherit from a common base class. However I want to be able to call members of the class without making a distinction of which class it particularly is. I was thinking of an interface for the last point I mentioned. Question : Would I'll be able to make my classes inherit this interface without directly inheriting the base class (i.e. the base class is inherited by interface)??:wtf:

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      An interface is just a contract of members, that a class that inherits the interface has to implement. An interface can not inherit from a class. What do you mean by calling a member without making a distinction of which class it is? You have to specify in what class a method is, or the compiler won't know where to look for it. What are you trying to do really? --- b { font-weight: normal; }

      1 Reply Last reply
      0
      • X XeoN Kc

        I have to design a library of classes. They are to inherit from a common base class. However I want to be able to call members of the class without making a distinction of which class it particularly is. I was thinking of an interface for the last point I mentioned. Question : Would I'll be able to make my classes inherit this interface without directly inheriting the base class (i.e. the base class is inherited by interface)??:wtf:

        K Offline
        K Offline
        Kevin McFarlane
        wrote on last edited by
        #3

        XeoN-Kc wrote:

        They are to inherit from a common base class. However I want to be able to call members of the class without making a distinction of which class it particularly is.

        Surely, this already does what you want? Kevin

        1 Reply Last reply
        0
        • X XeoN Kc

          I have to design a library of classes. They are to inherit from a common base class. However I want to be able to call members of the class without making a distinction of which class it particularly is. I was thinking of an interface for the last point I mentioned. Question : Would I'll be able to make my classes inherit this interface without directly inheriting the base class (i.e. the base class is inherited by interface)??:wtf:

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          XeoN-Kc wrote:

          They are to inherit from a common base class. However I want to be able to call members of the class without making a distinction of which class it particularly is.

          Well if you have a set of classes like this:

          public class A
          {
          public virtual void SomeMethod()
          {
          Console.WriteLine("Method from A");
          }
          }
          class B : A
          {
          public override void SomeMethod()
          {
          Console.WriteLine("Method from B");
          }
          }
          class C : A
          {
          public override void SomeMethod()
          {
          Console.WriteLine("Method from C");
          }
          }

          Now, if run this little program:

          static void Main()
          {
          A actuallyB = new B();
          A actuallyC = new C();
          A actiallyD = new D();
          actuallyB.SomeMethod();
          actuallyC.SomeMethod();
          actuallyD.SomeMethod();
          }

          Then the output is:

          Method from B
          Method from C

          You are referencing all as a reference of type A.

          XeoN-Kc wrote:

          Would I'll be able to make my classes inherit this interface without directly inheriting the base class

          If you are going to do it by interfaces then the base class no longer matters as you can reference it with the interface type instead. They can share the same base class, or have completely different base classes. Look at methods that implement the IDisposable interface. What do they have in common? Nothing, except for the IDisposable interface. Does this help? ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell

          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