A lot of questions that the teacher is usually asking us. They are all about the practical classes, while Java-related questions are in the Java course.
What's the design pattern for the class Group in TP Figures, which contains a lot of Figures. Note that Group is also a Figure.
It's the Composite design pattern.
In TP Tchat, in the method
void updateMessages(), which operations were intermediary?
stream.forEach((Message m) -> appendMessage(m));
stream = stream.filter(authorFilter);
Stream<Message> stream = messagesList.stream();
stream = stream.sorted();
The 2nd and the 4th ones, since in both we are consuming our stream to create a new one.
In TP Tchat, Controller implements
ListChangeListener<String>. What's the design pattern?
It's Observer/Observable design pattern.
In TP Tchat, the teacher used
Map<String, Color> colorMap = newTreeMap<String, Color>() to store the color(Color) for each user (String). What instructions are valid?
The 1st one since we have String-Color and the 4th one since
getmethod take a key and the key has the type String since we are associating for each username a color.
In TP Tchat, the class
ChatClient is handling the message (send/receive). It is M, V, or C in MVC?
I think it's M, since ChatClient can be viewed as a class interacting with a Database (the server here).
In TP Tchat, we were giving
Platform.runLater. True or False?
- the runnable classes were declared as inner classes (
- the runnable classes were declared as nested classes (
- we could have used lambda expressions
- we couldn't have used lambda expressions
- we could have used anonymous classes
The classes are not static, so they were declared as inner classes. We could have used a lambda expression, since Runnable is a functional interface. We could have used an anonymous class, it works no matter the class.
In TP Figures, what's the design pattern used when we are calling
equals(Figure f) inside
equals(Object obj) among Template Method, Equalizer, Decorator, and Adapter?
My first trough is the Template Method because
equals, hashcode, ...are methods defined in the template that is named
Object. But, since this is not "about equals" as it looks like this is about "the same method but more specialized" then I would pick Decorator=Wrapper because it looks like a Parser that becomes a XMLParser/PDFParser/... to me.
In TP Lists,
CollectionList<E> extends AbstractCollection<E> which is a
Collection<E> wrapping a
ForwardList<E>. What's the design pattern among Iterator, Decorator, Composite, and Adaptor?
First, I checked that
ForwardListwasn't a Collection. Hence, I would pick the pattern
Adaptorbecause we are providing an interface (a Collection) for our ForwardList.