nus-cs2103-AY2324S2 / forum

16 stars 0 forks source link

Practice Exam Part 2 abstract class implements interface #1022

Closed rertyy closed 6 months ago

rertyy commented 6 months ago

image

Why does ProgressWatcher not have +update(int)?

baskargopinath commented 6 months ago

@rertyy i think abstract classes dont have to provide implementations but concrete classes do

Li-Zizhen commented 6 months ago

@bgopi23 But the interface also doesn't have implementations?

baskargopinath commented 6 months ago

@Li-Zizhen thats the nature of interfaces, but any concrete classes extending it has to

Li-Zizhen commented 6 months ago

@bgopi23 Got it. Thank you.

aureliony commented 6 months ago

The abstract method can be shown:

image

rertyy commented 6 months ago

Hm if that's the case, why is {abstract} not shown for interface methods? Since by default interface methods are abstract unless it's a default method

damithc commented 6 months ago

Hm if that's the case, why is {abstract} not shown for interface methods? Since by default interface methods are abstract unless it's a default method

@rertyy <<interface>> already tells us the methods are abstract. Adding it to every method in the diagram doesn't add value but adds noise. This is the same reason why we don't use the abstract keyword when defining methods in a Java interface.

rertyy commented 6 months ago

But default methods for interfaces exist, and we can't differentiate if implicitly we assume abstract? At least for static there's underline

damithc commented 6 months ago

But default methods for interfaces exist, and we can't differentiate if implicitly we assume abstract? At least for static there's underline

@rertyy Default methods are just a recent quirk introduced into Java. It is more of an implementation detail, not a natural part of what we normally call an 'interface'. UML <<interface>> is not specific to Java, and models a more general concept of an interface.

If you must include a default method in a class diagram, you can indicate them using some other way e.g., using a custom stereotype <<default>> in front of the method, or a UML note.