1

I have defined an interface for a data structure type. I am trying to force whatever class implementing that interface to also implement two other interfaces (iterator and countable).

Is there a way to do this?

2 Answers 2

4

If you want to force it, you could declare that your interface extends the interfaces you required, e.g.

interface c extends a, b
{
   ...
}

Generally speaking though, you should probably be writing code which checks that an object has all the interfaces required for a particular operation before carrying it out. Makes things easier to maintain and extend in the long run...

Sign up to request clarification or add additional context in comments.

1 Comment

Oh nice, thanks! I was trying interface abc implements countable {}, giving a syntax error.
0

Have your interface implement them and then just pass on the abstract methods (i.e. don't implement the methods in your interface)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.