nus-cs2103-AY2324S2 / forum

16 stars 0 forks source link

Method overriding in class diagram #1057

Closed Li-Zizhen closed 5 months ago

Li-Zizhen commented 5 months ago

In the class diagram below, how do we know whether the process() in Bar is exactly the same as the one in Foo (since the process in Foo is not labeled as abstract) or it is Bar's overridden process()?

Moreover, if the process in Foo is not labeled abstract, it must be a concrete method?

image

marclamp commented 5 months ago

I think because process() in Foo is not declared abstract, it is a concrete method. Because of this, since there is process() in Bar as well, it overrides the process() method in Foo, this is from inheritance. If it was meant to be the exact same method then there would be no process() in Bar.

(Correct me if I'm wrong)

Li-Zizhen commented 5 months ago

@marclamp Thank for answering. But process() in Bar will get exactly the same process() in Foo by default. It should also show the process even if it is exactly the same process I think. Or do we not show the inherited method in subclass?

jinhanfromNUS commented 5 months ago

I was wondering about this as well.

Personally, I think if there is no overriding, then we do not need to write it out.

Below is the answer for practice part 2 image

From the answer we can see that, ProgressWatcher does not have +update(int) even it is implementing the Watcher interface. However, ProgressWatcher is an abstract class, so it might be different.

correct me if im wrong oo

damithc commented 5 months ago

Or do we not show the inherited method in subclass?

@Li-Zizhen Don't show unless it is overridden.

Li-Zizhen commented 5 months ago

Thanks for responding.