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. baseclass and a interface.

baseclass and a interface.

Scheduled Pinned Locked Moved C#
question
4 Posts 3 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.
  • J Offline
    J Offline
    Jarno Burger
    wrote on last edited by
    #1

    Now : -abstract classA -inherited classB with interfaceX -inherited classC with interfaceX -inherited classD with interfaceX -sealed classX that calls interfaceX But a lot of the commands in interfaceX , could be directly handled by the base class. Only some of the commands in interfaceX , are specific enough to be handled by the inherited class. I think i want : -abstract classA with interfaceX -inherited classB overides interfaceX.commandC -inherited classC overides interfaceX.commandC -inherited classD overides interfaceX.commandC -sealed classX that calls interfaceX Am i right , or am i missing something ??

    Jarno Burger Video Jockey

    S R 2 Replies Last reply
    0
    • J Jarno Burger

      Now : -abstract classA -inherited classB with interfaceX -inherited classC with interfaceX -inherited classD with interfaceX -sealed classX that calls interfaceX But a lot of the commands in interfaceX , could be directly handled by the base class. Only some of the commands in interfaceX , are specific enough to be handled by the inherited class. I think i want : -abstract classA with interfaceX -inherited classB overides interfaceX.commandC -inherited classC overides interfaceX.commandC -inherited classD overides interfaceX.commandC -sealed classX that calls interfaceX Am i right , or am i missing something ??

      Jarno Burger Video Jockey

      S Offline
      S Offline
      Saksida Bojan
      wrote on last edited by
      #2

      If you want to use second design, abstract class needs to have virtual method of commandC. example:

      public interface ITest
      {
      void Test();
      }

      public class T1 : ITest
      {
      public T1(){}
      public virtual void Test()
      {
      MessageBox.Show("From parent");
      }
      }

      public class T2 : T1
      {
      public T2(){}
      public override void Test()
      {
      MessageBox.Show("And I am parent's baby");
      }
      }

      T1 t1 = new T1();
      T2 t2 = new T2();
      ITest tt1 = (ITest)t1;
      ITest tt2 = (ITest)t2;
      t1.Test();
      t2.Test();
      tt1.Test();
      tt2.Test();

      In the end both design method woud work. In your case i would chose the second. But it is up to you to chose

      1 Reply Last reply
      0
      • J Jarno Burger

        Now : -abstract classA -inherited classB with interfaceX -inherited classC with interfaceX -inherited classD with interfaceX -sealed classX that calls interfaceX But a lot of the commands in interfaceX , could be directly handled by the base class. Only some of the commands in interfaceX , are specific enough to be handled by the inherited class. I think i want : -abstract classA with interfaceX -inherited classB overides interfaceX.commandC -inherited classC overides interfaceX.commandC -inherited classD overides interfaceX.commandC -sealed classX that calls interfaceX Am i right , or am i missing something ??

        Jarno Burger Video Jockey

        R Offline
        R Offline
        rhuiden
        wrote on last edited by
        #3

        I think that would be the way to go. I would also declare commandC in classA as abstract and force an override. Alternative: If you have a lot of commands that would have to overridden, you would want to use interface inheritance. -interfaceX would not have the definition for commandC. -You could then create interfaceY that inherits interfaceX and define commandC. -Classes B-D would inherit classA and implement interfaceY. -In classX you would call interfaceY. The only problem with your method: If you later change the definition of interfaceX you would have to change all the classes (classA would have to be modified even though there is no real change). This would also be true if you wanted to add a method. It all depends on the size of your classes/interface and how often they will change.

        J 1 Reply Last reply
        0
        • R rhuiden

          I think that would be the way to go. I would also declare commandC in classA as abstract and force an override. Alternative: If you have a lot of commands that would have to overridden, you would want to use interface inheritance. -interfaceX would not have the definition for commandC. -You could then create interfaceY that inherits interfaceX and define commandC. -Classes B-D would inherit classA and implement interfaceY. -In classX you would call interfaceY. The only problem with your method: If you later change the definition of interfaceX you would have to change all the classes (classA would have to be modified even though there is no real change). This would also be true if you wanted to add a method. It all depends on the size of your classes/interface and how often they will change.

          J Offline
          J Offline
          Jarno Burger
          wrote on last edited by
          #4

          thanx , you both cleaned my perspective with those abstract concepts !

          Jarno Burger Video Jockey

          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