You are on page 1of 5

INFO404 E Makeup exam

Advanced Programming November, 2022


Lebanese University D. May DEHAYNI Duration: 1 hr 30 mins
Faculty of Sciences I D. Samar TAWBI

P.S.: Make sure you have 5 pages. Documents are allowed.


Question I [pts]:
Answer the following questions and give a brief justification.
1. Does the implementation of the design patterns have to be object oriented in the meaning that we
should use inheritance and/or polymorphism?
_____________________________________________________________________________________________________

_____________________________________________________________________________________________________

_____________________________________________________________________________________________________

_____________________________________________________________________________________________________

______________________________________________

2. What are the objectives of the decorator pattern? Choose the right answer(s).
a. Enable the dynamic addition of functionality to an object.
b. Provide a uniform interface to a higher-level set of different interfaces in the system.
c. Allow the transfer of responsibility for creating objects to subclasses.
d. Hide the complexity of subsystems from the client.
e. Provide a substitute for the object to its control and protection.
f. Ensure that the class has one instance within the entire application.
g. Define an interface for creating objects.
h. Provide a flexible alternative to inheritance.
_____________________________________________________________________________________________________

_____________________________________________________________________________________________________

_____________________________________________________________________________________________________

_____________________________________________________________________________________________________

______________________________________________

3. Indicate for each case which design pattern you will use if you intend to:
a. Gather the information for an object before requesting its construction.
b. Defer for later the decision of which class to instantiate.
c. Construct a family of objects that share some characteristics.
d. Specify an object to create by giving an example from a copy of an existing object.
________________________________________________________________________________________________________

________________________________________________________________________________________________________

Page 1/5
________________________________________________________________________________________________________

________________________________________________________________

4. The following code is an implementation of which design pattern?


Interface Transporter {
void visit();
}
class Taxi implements Transporter {
public void visit() {System.out.println(“Traveling with taxi”);}
}
class Bus implements Transporter {
public void visit() {System.out.println(“Traveling with bus”);}
}
class Train implements Transporter {
public void visit() {System.out.println(“Traveling with train”);}
}
class Transportation {
Transporter tporter;
public Transportation(Transporter t) {
Answer: A True. Java doe not allow multiple
inheritance therefore adapter will always result in an object adapter
instead of a class adapter.
tporter = t;
}
public void accept_visitor() {
tporter.visit();
}
}
class Example {
public static void main(String[] args) {
Transportation context = new Transportation(new Taxi());
context.accept_visitor();
context = new Transportation(new Bus());
context.accept_visitor ();
}
}
a. Decorator
b. Visitor
c. Flyweight
d. Composite
e. Strategy

________________________________________________________________________________________________________

________________________________________________________________________________________________________

________________________________________________________________________________________________________

________________________________________________________________

5. Writing the Adapter pattern in Java will always result in an object adapter but never in a class
adapter
a. True
b. False

Page 2/5
________________________________________________________________________________________________________

________________________________________________________________________________________________________

__________________________________________________________________________

Question II [pts]:

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

Page 3/5
_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

Page 4/5
_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

_______________________________________________________________________________________

“Patience is bitter but its fruit is sweet.” J


Aristotle, Greek scientific and philosopher 384 BC – 322 BC
 Good Luck 

Page 5/5

You might also like