Correct Test Answers Flashcards
Which of the following applies specifically to Delegation and the Stratedy Design Pattern (circle all that apply):
A) Defines one or more static methods that encapsulate the details of object creations
b) Makes use of “implementation” classes that encapsulates a single implementation of an interface
c)Helps to reduce the space needed by a set of objects by removing the need to store duplicate objects containing the same data values.
d) Multiple implementation classes can be created when a variety of algorithms are needed to handle interface behaviors.
e)Specifies simple data objects made up of public data attributes containing copies of key data of the domain objects.
f) Helps to reduce application errors by centralizing common data values and removing the chance that an individual objects may change its own version of “type” based data.
g) Allows clients to make single call to retrieve multiple data elements of a domain object.
h) Allow implementation objects to be changes dynamically during application execution depending upon conditions.
B, D, H
Which of the Following Design Pattern(s) are often seen in addition to the pattern listed (circle all that apply for each pattern)
Facade
A) Strategy
B) Data Transfer Object (DTO)
C) Singleton
D) Factory
B
Which of the Following Design Pattern(s) are often seen in addition to the pattern listed (circle all that apply for each pattern)
Strategy
A) Factory
B)Null Object
C)Data Transfer Object(DTO)
D) Singleton
B
Which of the Following Design Pattern(s) are often seen in addition to the pattern listed (circle all that apply for each pattern)
Data Transfer Object(DTO)
A) Facade
B) Factory
C) Strategy
D) Null Object
A
Match the pattern or concept with the best Definition “A”-“M” (put one correct letter/definition next to the corresponding term - there are more definitions than are needed so all will not be used)
Identify the Design Pattern or Patterns present in the following java code (select all that apply)
public final class Envirnoment {
private static Environment instance;
private Environment(){}
public static Environment getInstance()
{
if(instance == null){
instance= new Environment();
}
return instance;
}
public double getTemperature(int x, int y){
//Complex weather-resourcfe code goes in here
}
public double getHumidty(int x, int y){
//Complex weather-resource code goes in here
}
}
Singleton
Data Transfer
Facade
Factory
Strategy
Null Object
None of these
All of these
Singletion
Facade
Identify the Design Pattern or Patterns present in the following java code (select all that apply)
public class CalMaker{
public static Calculator buildCalculator(
String style, boolean metric){
if(style.equals(“BASIC”)){
return BasicCalculator(metric);
}
else if (Style.equals(“SCIENTIFIC”){
return ScientificCalculator(metric);
}
else
{
return DefaultCalculator(metric);
}
}
}
Singleton
Data Transfer
Facade
Factory
Strategy
Null Object
None of these
All of these
Factory
Stategy
Identify the Design Pattern or Patterns present in the following java code. (Select all that apply).
public class CustomerData{
public String customerId;
public String lastName;
public String firstName;
public double avgPurchase;
public int purchaseCount;
public CustomerData(String c1, String ln,
String fn, double ap, int PC)
{
customerId = ci;
lastName = ln;
firstName = fn;
avgPurchase = ap;
purchaseCount = pc;
}
}
Singleton
Data Transfer
Facade
Factory
Strategy
Null Object
None of these
All of these
Data Transfer Object (DTO)
When should you attempt to handle an exception in place (w/ “try” & “catch”)? Circle the statement below that are TRUE
a) Any method called by a constructor must handle exception in place – it cannot propagate the exception
b) You should never propagate an exception – always handle it in place
c) when a method is working directly with the source of incoming data, you should handle the error in place and propagate an exception – do not handle it in place.
d) When in a method that was passed invalid data and you have no means to fix that data, you should throw and propagate an exception – do not handle it in place.
e) you should never handle an exception in place – always propagate it.
f) When in a method that throws an exception, you must handle the exception in place – do not propagate.
C,D
When did we say in class that an object that an object should never give out reference that it owns and maintains (i.e., data members that are reference type). Circle only one option below)
A) this would violate information Hiding
B) Because it would result in generating a duplicate object.
C) Because it would always result in returning object
D) we didn’t say that in class
A.
What does the Open-Closed Principle imply? Circle only one option below
A) A good design is open to open to addition but closed to modification
B) A good design is open to inheritance but closed to interfaces
C) A good design should couple classes as tightly as possible
D) A good design is open to modification but closely to addition
E) None of the above
A.
What does the Single-Responsibilty Principle imply? Circle only one option below
A) A class should have only one instance
B) A class should have only one relationship to other classes.
C) A class should have only one parent class.
D) A class should have only one reason to change.
E) None of the above
D.
In Java, class names follow the _____________naming style
Upper camel Case
In Java, data members and methods names follow the _________________naming style
Lower Camel Case
When data parameters are passed to a constructor or a modifier (set method) you should be sure to:(Circle only one option)
A) Error-checking the incoming values to make sure they are legitimate values before using them
B) Directly assign the incoming values to the appropriate data members, nothing else should be done
C) Never assign incoming values to any data members
D) None of the above
A.