book says that interfaces specify behavior without implementing it. That doesn't really explain much to me.
If you could please look at what I've done and tell me if I am using the interface properly, I would really appreciate it. What I've done seems to work. But I don't understand why I would want to use an interface. It seems to me that it's some way to pass objects around and use methods easier? But I am not sure since it seems I am repeating methods anyways.
If you think it could be done in a better way, I would love to know how. But my main hope is that I am doing this correctly and could use some help with understanding how to use an interface.
Thanks so much in advance.
VB Code:
class Arm : IBendable { public Arm() { } public void Raise() { Console.WriteLine("Raising arm up."); } public void Bend() { this.Raise(); } }VB Code:
class Spoon : IBendable { public Spoon() { } public void Eat() { Console.WriteLine("Eating from the spoon."); } public void Bend() { this.Eat(); } }VB Code:
namespace Prog6_18 { public interface IBendable { // Any class that implements the IShape interface // must define the following methods: void Bend(); } }VB Code:
class Prog6_18 { static void Main(string[] args) { Spoon childsSpoon = new Spoon(); Arm childsArm = new Arm(); EatFood(childsArm); EatFood(childsSpoon); } public static void EatFood(IBendable a) { a.Bend(); } }




Reply With Quote