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. Changing from an Interface to an Abstract

Changing from an Interface to an Abstract

Scheduled Pinned Locked Moved C#
question
3 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
    joshp1217
    wrote on last edited by
    #1

    Okay I have this Interface: interface myInterface { public void visible(bool view); } I was implementing the visible method in my other classes like this: visible(bool view) { if(view) { this.Left = -500000; blah blah blah } else { this.left = 0; blah blah blah } } Okay I need to change my interface to an abstract class, so i can just implement the visible method one time in the abstract, but i can't use "this.Left" in the abstract because it doesnt contain a method for "Left". It is probably a simple solution to this but how do I get this.Left, this.dock etc. to be available for use in my abstract class?

    J J 2 Replies Last reply
    0
    • J joshp1217

      Okay I have this Interface: interface myInterface { public void visible(bool view); } I was implementing the visible method in my other classes like this: visible(bool view) { if(view) { this.Left = -500000; blah blah blah } else { this.left = 0; blah blah blah } } Okay I need to change my interface to an abstract class, so i can just implement the visible method one time in the abstract, but i can't use "this.Left" in the abstract because it doesnt contain a method for "Left". It is probably a simple solution to this but how do I get this.Left, this.dock etc. to be available for use in my abstract class?

      J Offline
      J Offline
      Josh Smith
      wrote on last edited by
      #2

      Make an abstract property get-set called Left which the derived classes override. :josh: My WPF Blog[^]

      1 Reply Last reply
      0
      • J joshp1217

        Okay I have this Interface: interface myInterface { public void visible(bool view); } I was implementing the visible method in my other classes like this: visible(bool view) { if(view) { this.Left = -500000; blah blah blah } else { this.left = 0; blah blah blah } } Okay I need to change my interface to an abstract class, so i can just implement the visible method one time in the abstract, but i can't use "this.Left" in the abstract because it doesnt contain a method for "Left". It is probably a simple solution to this but how do I get this.Left, this.dock etc. to be available for use in my abstract class?

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        further to Josh's suggestion, the point of an abstract class is to abstract the functionality (as the name implies). Something like this would satisfy public abstract class AbstractThing : myInterface { protected abstract void SetVisible(); protected abstract void SetInvisible(); public void Visible(bool view) { if(view) SetVisible(); else SetInvisible(); } } then your derived class, which has the Left property defined. public DerivedThing : AbstractThing { protected override void SetInvisible(){ this.Left = -50000; } protected override void SetVisible(){ this.Left = 0; } } or say you derive it and you wantr different behaviour for SetVisible and SetInvisible..eg/ public OtherDerivedThing : AbstractThing { protected override void SetInvisible(){ this.Visible= false; } protected override void SetVisible(){ this.Visible = true; } } --- How to get answers to your questions[^] -- modified at 10:36 Friday 14th July, 2006

        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