philjack
philjack

Reputation: 89

Overriding interface method- implementation in Superclass

Is it ok if a subclass implements an interface and instead of overriding the method it puts the method in the superclass (method with same name and arguments in superclass). Diagramm 1

Or is it better to implement it like in the following Diagramm 2 ?

Upvotes: 0

Views: 29

Answers (1)

Hendrik Rombach
Hendrik Rombach

Reputation: 340

Whether or not it is legal depends on the language you're using.

I see no reason to not implement it as shown in Diagram 2, provided AbstractSuperClass fulfills the promise of interface1.

This way any other future subclasses of AbstractSuperClass would also be able to be type-checked against interface1.

Upvotes: 1

Related Questions