Design Patterns - J2EE and GoF Patterns

Test your knowledge of J2EE and Gang of Four (GoF) design patterns including behavioral, creational, and structural patterns such as Singleton, Factory, Strategy, Observer, Decorator, and more.

15 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

What is a Decorator pattern?

  1. decouple an abstraction from its implementation so that the two can vary independently
  2. One class takes in another class, both of which extend the same abstract class, and adds functionality.
  3. Assembles group of objects with same signature
  4. One class controls the creation of and access to objects in another class.
Question 2 Multiple Choice (Single Answer)

What is a Façade pattern?

  1. The reusable and variable parts of a class are broken into two classes to save resources
  2. One class controls the creation of and access to objects in another class.
  3. One class takes in another class, both of which extend the same abstract class, and adds functionality.
  4. One class has a method that performs a complex process calling several other classes.
Question 3 Multiple Choice (Single Answer)

Which of the following are types of Creational Patterns?

  1. Adapter, Bridge and Decorator.
  2. Singleton, Builder and Factory Method.
  3. Facade, Flyweight and Proxy.
  4. Iterator, Observer and Template.
Question 4 Multiple Choice (Single Answer)

A ------------- is a direct stand-in for another class and it typically has the same interface as that class because it implements a common interface or an abstract class

  1. Façade Pattern.
  2. Decorator Pattern.
  3. Proxy Pattern.
  4. Adapter Pattern.
Question 5 Multiple Choice (Single Answer)

Example of Decorator pattern in Java API?

  1. java.util.List
  2. java.lang.String
  3. java.io.BufferedInputStream.
  4. None of the above.
Question 6 Multiple Choice (Single Answer)

The -------------- Method pattern should be used to implement the invariant parts of an algorithm once and leaves it up to subclasses to implement the behavior that can vary.

  1. Strategy Pattern.
  2. Template Pattern.
  3. Observer Pattern.
  4. None of the above.
Question 7 Multiple Choice (Single Answer)

The Java API uses this pattern in the event model of its AWT/Swing Classes

  1. Strategy Pattern.
  2. Template Pattern.
  3. Observer pattern.
  4. None of the above.
Question 8 Multiple Choice (Single Answer)

Which pattern prescribes recursive composition for complex objects?

  1. Composite Pattern
  2. Strategy Pattern
  3. Observer Pattern
  4. Factory Pattern
Question 9 Multiple Choice (Single Answer)

Which pattern is used to allow different implementations of an algorithm or operation to be selected dynamically at runtime?

  1. Façade Pattern.
  2. Adapter Pattern
  3. Strategy Pattern.
  4. Factory pattern.
Question 10 Multiple Choice (Single Answer)

Which Pattern is used when it must be decided at run time which one of the several compatible classes is to be instantiated?

  1. Singleton Pattern
  2. Façade Pattern.
  3. Factory Pattern.
  4. Adapter Pattern.
Question 11 Multiple Choice (Single Answer)

What Modifier needs to be added in order to make the below function as Singleton Class? ----------- -------- Connection getConnection() throws Exception{ return new Connection(); }

  1. private, final.
  2. protected, static
  3. public, static
  4. public, final.
Question 12 Multiple Choice (Single Answer)

Suppose I have to code a program to draw 1000 circles with 6 different colors – Which Structural Pattern approach would help?

  1. Façade.
  2. FlyWeight.
  3. Decorator.
  4. Adpater
Question 13 Multiple Choice (Single Answer)

Which Behavioral Pattern would help in parsing and translate a Specific Expression?

  1. Command
  2. Interpreter
  3. Observer
  4. Iterator.
Question 14 Multiple Choice (Single Answer)

Which Behavioral Pattern move through a list of collection or aggregated objects without knowing its internal representations?

  1. Command
  2. Interpreter
  3. Mediator.
  4. Iterator.
Question 15 Multiple Choice (Single Answer)

If I need to access Multiple Data Sources like Legacy Systems, B2B, LDAP – Which of the below J2EE Pattern would suit?

  1. Data Access Object.
  2. MVC
  3. Business Delegate
  4. Service Locator.