Chapter 3 - Types and Interfaces Flashcards

1
Q

interface

A
  • contains abstract methods which don’t have an implementation
  • use implements keyword to tie a class to an interface; this class is a subtype of the interface and must implement the abstract methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Comparable

A
  • uses o1.compareTo(o2)
  • class that implements this method needs to use keyword “implements Comparable”; only one way to compare using this method
  • returns: 0 if equal; negative if o1 < o2; positive if o1 > o2
  • use Collections.sort(list) to then sort the objects based on implemented compare method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Comparator

A
  • separate class from the element type we’re comparing
  • create multiple separator classes that implement Comparator that each have their own method to compare to objects (implement method compare(o1, o2))
  • call Collections.sort(List<T> list, Comparator)</T>
  • use static factory methods to define Comparator classes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

static factory method for Comparator createByRankComparator

A

pg. 63 textbook

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

SWITCH STATEMENT antipattern

A

relying on a global variable that stores the required strategy and switching strategies based on this flag

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

Iterable interface

A
  • implement Iterator<T> iterator()</T>
  • for lists (eg. aCards) -> return aCards.iterator(); suffices
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

ITERATOR design pattern

A

provides a way to access the elements encapsulated within another object without exposing the underlying representation

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

STRATEGY design pattern

A
  • define a family of algorithms, encapsulate each one, and make them interchangeable (have an interface that is implemented by multiple classes that each have their own strategy)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

dependency injection technique

A
  • inject the dependency into the client class (usually using a constructor)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly