2. Java 7: Design Patterns Flashcards

1
Q

What are the Java 7 design patterns you need to know?

A
  • Singleton pattern
  • Composition pattern
  • DAO pattern
  • Factory pattern
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are two ways to make the Sinlgeton pattern thread-safe?

A
  • Make the whole getInstance method synchronized (performance impact because it will always enter a synchronized method)
  • Add a synchronized block to the getInstance methodm (less performance impact) f.e:
MySingleton getInstance() {
   if(instance == null) {
      synchronized(MySingleton.class) {
         if(instance == null) { instance = new MySingleton(); }
      }
   }
   return instance;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can be tested if TypeB needs inheritance?

A

Does TypeB want to expose the complete interface of TypeA so that TypeB van be used where TypeA is expected?

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

How can be tested if TypeB needs composition?

A

Does TypeB only want some part of the behaviour of TypeA exposed?

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

What is a DAO?

A

Data Access Object. An object that provides a abstract interface to some type of database or persistence layer.

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