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.
Questions
What is a Decorator pattern?
- decouple an abstraction from its implementation so that the two can vary independently
- One class takes in another class, both of which extend the same abstract class, and adds functionality.
- Assembles group of objects with same signature
- One class controls the creation of and access to objects in another class.
What is a Façade pattern?
- The reusable and variable parts of a class are broken into two classes to save resources
- One class controls the creation of and access to objects in another class.
- One class takes in another class, both of which extend the same abstract class, and adds functionality.
- One class has a method that performs a complex process calling several other classes.
Which of the following are types of Creational Patterns?
- Adapter, Bridge and Decorator.
- Singleton, Builder and Factory Method.
- Facade, Flyweight and Proxy.
- Iterator, Observer and Template.
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
- Façade Pattern.
- Decorator Pattern.
- Proxy Pattern.
- Adapter Pattern.
Example of Decorator pattern in Java API?
- java.util.List
- java.lang.String
- java.io.BufferedInputStream.
- None of the above.
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.
- Strategy Pattern.
- Template Pattern.
- Observer Pattern.
- None of the above.
The Java API uses this pattern in the event model of its AWT/Swing Classes
- Strategy Pattern.
- Template Pattern.
- Observer pattern.
- None of the above.
Which pattern prescribes recursive composition for complex objects?
- Composite Pattern
- Strategy Pattern
- Observer Pattern
- Factory Pattern
Which pattern is used to allow different implementations of an algorithm or operation to be selected dynamically at runtime?
- Façade Pattern.
- Adapter Pattern
- Strategy Pattern.
- Factory pattern.
Which Pattern is used when it must be decided at run time which one of the several compatible classes is to be instantiated?
- Singleton Pattern
- Façade Pattern.
- Factory Pattern.
- Adapter Pattern.
What Modifier needs to be added in order to make the below function as Singleton Class? ----------- -------- Connection getConnection() throws Exception{ return new Connection(); }
- private, final.
- protected, static
- public, static
- public, final.
Suppose I have to code a program to draw 1000 circles with 6 different colors – Which Structural Pattern approach would help?
- Façade.
- FlyWeight.
- Decorator.
- Adpater
Which Behavioral Pattern would help in parsing and translate a Specific Expression?
- Command
- Interpreter
- Observer
- Iterator.
Which Behavioral Pattern move through a list of collection or aggregated objects without knowing its internal representations?
- Command
- Interpreter
- Mediator.
- Iterator.
If I need to access Multiple Data Sources like Legacy Systems, B2B, LDAP – Which of the below J2EE Pattern would suit?
- Data Access Object.
- MVC
- Business Delegate
- Service Locator.