Correct Test Answers Flashcards

1
Q

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.

A

B, D, H

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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)

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

Singletion
Facade

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

A

Factory
Stategy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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

A

Data Transfer Object (DTO)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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.

A

C,D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

A.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A

D.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

In Java, class names follow the _____________naming style

A

Upper camel Case

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In Java, data members and methods names follow the _________________naming style

A

Lower Camel Case

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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

A.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The Delegation concept refers to: (Circle only one option):

A) A Relationship b/w objects where one object forwards certain method calls to another objects.

B) A named collection of method definitions (w/o implementations)

C) Restricting instatiation of a class to one object.

D)The Creation of a class with a unified interface to a set of interfaces (publicly exposed methods) In a subsystem

E) None of the above.

A

A

17
Q

The Separation principle refers to

A)The separation of an interface from an implementation

B)The Seperation of a class from its data members

C) The separation of object creation to a specialized class

D) None of the above

A

A.

18
Q

What does the Liskov Substitution Principle imply
A) You should be able to substitute a more generic type when a specific type is indicated

B) The inheritance relationship can be substituted for delgeation in certain situations

C) Subsitution should be favored over inheritance

D) You should be able to substitute Object for any class object

E) None of the above`

A

E.

19
Q

What does the Dependency Inversion Principle imply

A) Design to an implementation, not to an interface

B) Design using inheritance whenever possible, interfaces as a last resort.

C) Design to an interface, not to an implementation

D) Design the most specific relationships as is possible

E) None of the above

A

C

20
Q

What Does the interface Segregation principle imply?

A) Classes should not be forced to depend upon interfaces that they do not use.

B) A good design should not use interfaces.

C) Classes should implement as many interfaces as is possible

D) Classes should be distinct and separate from interfaces

E) None of the above

A

A

21
Q

What is the difference b/w comparing using “==” and “equals” (assuming “.equals” has been appropriately created for a user class). [Circle the statements that are TRUE]

”==” Does a byte comparison of the two objects.

”==” Does a comparison of the memory address of the two objects.

”==” Can ONLY be used w/ native types like int, long, char, etc., NOT references.

”==” Does a comparison using the “.equals” method defined for the objects being compared.

”==” Does a comparison b/w all public data attributes of the objects being compared.

“.equals” Does a byte to byte comparison of the 2 objects.

“.equals” Does a byte comparison address of the objects.

“equals” can ONLY be used w/ natives types like int, long, char, etc., NOT references

“.equals” results in a programmer-defined comparison of data elements b/w the two objects.

“.equals” Does a comparison b/w all public attributes of the objects being compared

A

”==” Does a comparison of the memory address of the two objects.

“.equals” results in a programmer-defined comparison of data elements b/w the two objects.

22
Q

What Object Oriented Design Principle does the following code example violate and why? Circle one principle answer (A-E) and the one Reason answer (A-E)

Principle:
A) Interface Segregation Principle
B) Inheritance
C) Encapsulation
D)Information Hiding
E) Composition

Reason:
A) Point should have a parent class
B) PointOps should be an interface implemented by Point
C) PointOps should own an instance of Point
D) Data in Point is needed by the methods in PointOps.
E) Data in Point should be public, not private

A

C for Principle, D for Reason.