Final Review Flashcards

1
Q

Test-Driven Development requires one to define contracts and interfaces before writing test cases. T/F ?

A

True

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

Functional Decomposition

A

breaking down a complex system into smaller, functional parts.

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

ADT

A

An abstract class or interface that contains a description of all possible operations it can do on a data type but not its implementation

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

Abstraction function

A

An abstraction function

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

Representation Invariant

A

A representation invariant is a condition or property that must always be true for the internal state of an object or data structure.

A condition inside a method that most hold. A condition about its implementation

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

Difference between a public invariant and RI

A

A public invariant is a condition that must hold for a public method to function properly

Represention Invariant is a condition that must hold in a methods implemenation

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

Dependency Injection

A

Its is like parameterising but for classes,
During the construction, inject info

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

What to talk about in @post

A
  • The result
  • The variables that are modified
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which array can have null values

A

Can have null values:
- String array

Can’t have null values:
- Integer array
- Set integers

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

Dependency Inversion Principle

A
  • high-level modules should not depend upon low-level modules, but that both should depend upon abstractions.
  • abstractions should not depend upon details, but that details should depend upon abstractions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Key words

A

Testability
Resusibility
Understandability
Maintainability
Modifibility

Coupling
Cohesion

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

Describe the main steps (w.r.t. declaration and execution) for client code to use the SwingWorker class.

A

i. (Static aspect; declaration) By subclassing SwingWorker and overriding the doInBackground() and done() methods.

ii. (Dynamic aspect; execution) The resulting SwingWorker subclass must be in- stantiated for each run. The background thread is activated by calling execute().

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

Which of the following design patterns are used for Java’s SwingWorker?

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

For ADTs, we distinguish between specification and implementation. Which of the following are part
of the specification of an ADT?

A
  • Contracts for individual operations
  • Zero or more public invariants
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

For ADTs, we distinguish between specification and implementation. Which of the following are part
of the Implemenation of an ADT?

A
  • An abstraction function
  • A representation invariant.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the advantages of throwing a Java exception instead of returning a special value to signal
a violated precondition?

A
  • Exceptions can carry additional information
  • Exceptions are typed and can have messages, allowing for specific exception handling and more clear
    information while debugging and reading stack traces
  • The programmer might forget to check the return value; exceptions cannot be ignored so easily
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

In the context of abstract data types, what is encapsulation, and why is it useful?

A
  • ADT bundles and hides implementation details (data
    representation and operation implementations; using class mechanism), separate from specification in
    ADT (using interface or abstract class mechanism).
  • Encapsulation in ADT makes it impossible for clients to directly depend
    on implementation details
  • Encapsulation in ADT makes it possible to change the encapsulated
    details (i.e. implementation) without affecting client code
18
Q

What is functional decomposition?

A

This is a design technique that carries out Divide & Conquer (solely) with procedural
abstraction.

Decomposition is driven by considering the required functionality of the
program being designed. In requirements, functionality can often be discovered in the verbs.

Design guidelines:
- aim for single-purpose, general methods (SRP = Single Responsibility
Principle),
- low coupling
- high cohesion
- low complexity (no deeply nested control
structures)
- avoid code duplication (DRY = Don’t Repeat Yourself). Parameters, return
values, global versus local data, recursion.

19
Q

Explain one disadvantage of functional decomposition.

A

Disdvantages of Divide & Conquer
- Top-level divisions are hard to make: can have big consequences. Need experience and
need to experiment (try alternatives).

20
Q

Advantages of automated test cases on manual ones

A
  • Manual testing is tedious, time consuming, and error prone.
  • Automated test cases are more convenient, faster, and more reliable.
  • They offer the ability to (re)run all test cases, and report on the results.
  • It is easier to inspect the results of automated test cases.
21
Q

Name at least four reasons why it is not a good idea to include unnecessary test
cases.

A
  • Costs extra test development time.
  • Gives false impression of application code quality.
  • Gives false impression of test quality.
  • Costs extra test time when executing tests.
22
Q

What is the purpose of the SwingWorker class of Java?

A

It makes it easy to run some code in a background thread, and still interact with it in a
controlled way.

23
Q

Describe the two main steps for client code to use the SwingWorker class?

A
  1. Some Swing component methods are labelled “thread safe” in the API specification: these
    can be safely invoked from any thread.
  2. All other Swing component methods must be invoked from the event dispatch thread.
24
Q

Explain two design patterns which play a role in the SwingWorker, and what that
role is.

A
  1. SwingWorker acts as a Facade for the Java Thread facilities.
  2. It uses the Template Method pattern to let clients define steps:
    - Which computation to do in background: doInBackground()
    - How to handle intermediate results: process()
    - What to do with the final result: done()
25
Q

What are the benefits of implementing test cases before, rather than after, implementing a
software product?

A
  • It encourages analysis of interfaces and contracts before implementing them.
  • It helps stabilize interfaces and contracts before implementing them.
  • It allows you to focus on implementing the module and getting it to work,
    without being interrupted by test case development.
26
Q

Describe the structure of a test case for robustness using the Java try statement and how
it works.

A

i. Call the method under test in a try block such that its precondition is violated.
ii. If the next statement is reached (no exception was thrown), the test case fails.
iii. Catch the thrown exception in a catch block.

27
Q

What does it mean for a concrete class C to depend on another concrete class D?

A

That class C cannot be compiled without having class D as well.

28
Q

What are two concrete disadvantages of such a dependence? Class c depends on class D

A

Applying the Dependency Inversion Principle (DIP): Don’t make a class (C) dependent on concrete code (D), rather make both depend on an abstraction.
* Introduce an interface for class D.
* Let class D implement that interface.
* Make class C dependent on that interface.
* Let client code of class C configure it at runtime to use class D (Dependency
Injection).

29
Q

What is an ADT

A

An abstract data type makes available, for use in programs, a set of abstract values together with operations on those values.

Its implementation is encapsulated and not directly accessible by client code, so that client code does not depend on the
implementation.

30
Q

Why are ADTs useful? Explain your answer.

A

Implementation code of an ADT can be changed without affecting (correctness of)
client code. This is useful, because it limits the consequences of making changes to
implementations.
It also makes it easier to have multiple implementations of the same ADT.

31
Q

What kinds of code and documentation must be delivered to implement an ADT?

A

(c) * Code:
– A data representation (in terms of concrete types or other ADTs)
– Implementations of all operations
* Documentation:

– representation invariant, stating the condition under which the data representation is valid; that is, when it represents an abstract value.

– abstraction function, mapping a valid data representation to the corresponding abstract value.

32
Q

Design Patterns

A

T emplate
I teration
F acade
F actory
S ingleton
S tate
S trategy
A daptor
D ecorator
O bserver
C ommand
C ompound command
C omposite

13

33
Q

Factory Method: Relation with different design patterns

A

You can use Factory Method along with Iterator to let collection subclasses return different types of iterators that are compatible with the collections.

Factory Method is a specialization of Template Method. At the same time, a Factory Method may serve as a step in a large Template Method.

34
Q

Factory: Pros and Cons

A

Pros
- You avoid tight coupling between the creator and the concrete products.
- Single Responsibility Principle. You can move the product creation code into one place in the program, making the code easier to support.
- Open/Closed Principle. You can introduce new types of products into the program without breaking existing client code.

Cons
- The code may become more complicated since you need to introduce a lot of new subclasses to implement the pattern. The best case scenario is when you’re introducing the pattern into an existing hierarchy of creator classes.

35
Q

Adapter: Relations with other Design Patterns

A

Adapter provides a completely different interface for accessing an existing object. On the other hand, with the Decorator pattern the interface either stays the same or gets extended. In addition, Decorator supports recursive composition, which isn’t possible when you use Adapter.

Facade defines a new interface for existing objects, whereas Adapter tries to make the existing interface usable. Adapter usually wraps just one object, while Facade works with an entire subsystem of objects.

Bridge, State, Strategy (and to some degree Adapter) have very similar structures. Indeed, all of these patterns are based on composition, which is delegating work to other objects. However, they all solve different problems. A pattern isn’t just a recipe for structuring your code in a specific way. It can also communicate to other developers the problem the pattern solves.

36
Q

Adapter: Pros and Cons

A

Pros:
- Single Responsibility Principle. You can separate the interface or data conversion code from the primary business logic of the program.
- Open/Closed Principle. You can introduce new types of adapters into the program without breaking the existing client code, as long as they work with the adapters through the client interface.

Cons:
- The overall complexity of the code increases because you need to introduce a set of new interfaces and classes. Sometimes it’s simpler just to change the service class so that it matches the rest of your code.

37
Q

a.has(i)

A

Means that wether or not a contains this value

38
Q

Finding the max value in an list

A

\max i; a.has(i); a[i]

39
Q

Contract don’t forget

A

Don’t forget to write the header of the method, with also its exceptions

void multiplyArraysWithFactor(double[] a, double factor, double[] b)
throws NullPointerException, IllegalArgumentException

40
Q

What to do when talking about prinicples

A

Write its definition

41
Q

inherits == extend

A
42
Q

interface == implement

A