Changing from an Interface to an Abstract
-
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?
-
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?
Make an abstract property get-set called Left which the derived classes override. :josh: My WPF Blog[^]
-
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?
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