nus-cs2103-AY2021S2 / forum

10 stars 0 forks source link

Question on Practice Exam Part 2 Class Diagram #363

Open glatiuden opened 3 years ago

glatiuden commented 3 years ago

Hi! I was attempting the practice exam part 2 earlier on and noticed that the update() method in the Watcher interface is set as public (+). I understand that interface methods doesn't allow access modifiers, so I'm a bit confused with the solution. Is it fine if I declare it as ~ or leave it empty instead? Thank you!

image

tlylt commented 3 years ago

Hi,

All abstract, default, and static methods in an interface are implicitly public, so you can omit the public modifier.

See: https://docs.oracle.com/javase/tutorial/java/IandI/interfaceDef.html#:~:text=The%20public%20access%20specifier%20indicates,same%20package%20as%20the%20interface.


So I would say either + or leave it empty, but not ~

kouyk commented 3 years ago

So I would say either + or leave it empty, but not ~

I agree, protected doesn't make any sense since interfaces are API contracts. Though with that said, it is possible to have private methods within an interface with its own set of rules, see here if interested. But those private interface methods shouldn't be represented anyway, since it affects the high level views that UML diagrams are supposed to show, hence leaving it empty should be unambiguous that the interface methods stated are all public.

tlylt commented 3 years ago

So I would say either + or leave it empty, but not ~

But those private methods shouldn't be represented anyway, since it affects the high level views that UML diagrams are supposed to show, hence leaving it empty should be unambiguous that the interface methods stated are all public.

I do see private methods/variables appearing in some of the textbook's UML examples though, not sure if it is an actual concern?

kouyk commented 3 years ago

I do see private methods/variables appearing in some of the textbook's UML examples though, not sure if it is an actual concern?

We can probably discuss the relevant examples? At least from what I can gather, the private interface methods seems to be more relevant for implementation rather than with the public contract aspect of the interface.

tlylt commented 3 years ago

I do see private methods/variables appearing in some of the textbook's UML examples though, not sure if it is an actual concern?

We can probably discuss the relevant examples? At least from what I can gather, the private interface methods seems to be more relevant for implementation rather than with the public contract aspect of the interface.

Oh you are referring only to private methods in the context of the interface, then I have no examples. Class wise private methods and variables do appear to be included in UML.

prerthan99 commented 3 years ago

Hi! I was attempting the practice exam part 2 earlier on and noticed that the update() method in the Watcher interface is set as public (+). I understand that interface methods doesn't allow access modifiers, so I'm a bit confused with the solution. Is it fine if I declare it as ~ or leave it empty instead? Thank you!

image

Hi, I was just wondering if someone could explain why there an update(int) method for UiWidget? I know it inherits from ProgressWatcher which in turn implements Watcher (which is where I assume to method comes from) but do we have to write all the methods that are inherited from? thanks

damithc commented 3 years ago

but do we have to write all the methods that are inherited from?

There is no special treatment for inherited methods. They are optional to show, just like regular methods.

prerthan99 commented 3 years ago

@damithc, got it, thanks prof