Design Patterns and Principles Flashcards

1
Q

What modifiers are automatically added to interface methods?

A

public, to all methods

abstract, to all methods that are non-static and non-default

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

Functional Interface

A

An interface that contains a single abstract method

Note: Can contain any number of static or default methods as well, as long as there is exactly one ABSTRACT method

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

@FunctionalInterface

A

Indicates that the following interface should be a functional interface.

If the interface has more than one abstract method or no abstract methods at all, the code will not compile.

Note: Functional interfaces can have any number of default and static methods, it’s just required that they have exactly one abstract method

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

java.util.function.Predicate interface?

A

An interface that you can use for the common need to use a lambda that returns a boolean

public interface Predicate {
public boolean test(T t);
}

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

is‐a relationship

A

the property of an object being an instance of a data type

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

has‐a relationship

A

the property of an object having a named data object or primitive as a member

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

Design Pattern

A

an established general solution to a commonly occurring software development problem

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

Creational Patterns

A

a type of software design pattern that manages the creation of objects within an application

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

Level of Indirection

A

a general term for solving a software design problem by conceptually separating the task into multiple levels.

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

Singleton Pattern

A

a creational pattern focused on creating only one instance of an object in memory within an application, sharable by all classes and threads within the application.

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

Singleton

A

The object created with the singleton pattern.

They should be private static, and will often be called “instance”

The constructor in the class should be private

public class HayStorage {

 private HayStorage() {}

 private static final HayStorage instance = new HayStorage();

 public static HayStorage getInstance() { 
      return instance;
  } }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Lazy Instantiation

A

Creating a reusable object the first time it is requested rather than when the class is first used

Reduces memory usage and improves performance when an application starts up.

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

Immutable Object Pattern

A

a creational pattern based on the idea of creating objects whose state does not change after they are created and can be easily shared across multiple classes

1) Use a constructor to set all properties of the object.
2) Mark all of the instance variables private and final.
3) Don’t define any setter methods.
4) Don’t allow referenced mutable objects to be modified or accessed directly.
5) Prevent methods from being overridden.

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

The type of the object determines…

A

which properties exist within the object in memory

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

The type of the reference to the object determines…

A

which methods and variables are accessible to the Java program

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

JavaBean

A

A design principle for encapsulating data

17
Q

What level of access should properties have when encapsulating data?

A

private

18
Q

How should you name your getter for non-boolean properties when encapsulating data?

A

Begin the method name with “get”

19
Q

How should you name your getter for boolean properties when encapsulating data?

A

Either begin the method name with “get” or “is”

**Note”: If dealing with a wrapper class Boolean then you must use “get”

20
Q

How should you name your setter method when encapsulating data?

A

Begin the method name with “set”

21
Q

What must the rest of the setters and getters method names have after the initial “set”/”get”/”is”?

A

The property name with the first letter uppercase