nus-cs2103-AY2223S2 / forum

12 stars 0 forks source link

Question about UML Notation for Design Patterns #396

Open FredericChow00 opened 1 year ago

FredericChow00 commented 1 year ago

Question regarding Singletons:

  1. Where does the <<role/purpose>> come in for the Singletons? Is it in the naming of the singleton?
  2. I realize that Singletons have <<Singleton>> UML Notation above the class name, I just wanted to clarify that according to the textbook it is optional. And also Facade Classes would not require such an UML Notation?

image

hingen commented 1 year ago

Where does the <<role/purpose>> come in for the Singletons? Is it in the naming of the singleton?

image

It's just a way to specify that the class is a singleton. There isn't a specific programming language construct for it like in the case for <<interface>> or {abstract}.

Suppose <<Singleton>> is removed, now it becomes a bit unclear whether the class is a singleton or not. In practice, singleton classes often have a lot more methods and variables than what is shown in the example. The specific names theOne and getInstance() (from my understanding) aren't conventions either and different developers may name them differently or even implement Singletons differently (e.g. using a Singleton<T> generic class). Hence, determining whether something is a singleton purely base on the methods and variables is not as straightforward as it may look. Thus the <<Singleton>> notation is good for being explicit and clear.

I realize that Singletons have <> UML Notation above the class name, I just wanted to clarify that according to the textbook it is optional.

Seems like the textbook does imply that it is optional. From what I gather, most things in UML class diagrams are optional. The bare minimum seems to just be class names (for representing classes) and a solid line (for representing associations). But then again, you can omit specific classes and associations (as many have done in the TP) if they are not necessary for what you're trying to convey. Not sure what the convention is for our final exam though.

core-uml-class

And also Facade Classes would not require such an UML Notation?

Pretty sure you can specify it if you feel it is necessary. I remember one of the tutorials had a UML class diagram where <<Facade>> was specified. I have no screenshots of it though :(

FredericChow00 commented 1 year ago

Got it thanks so much for the help! @hingen