Final Review Flashcards
(42 cards)
Test-Driven Development requires one to define contracts and interfaces before writing test cases. T/F ?
True
Functional Decomposition
breaking down a complex system into smaller, functional parts.
ADT
An abstract class or interface that contains a description of all possible operations it can do on a data type but not its implementation
Abstraction function
An abstraction function
Representation Invariant
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
Difference between a public invariant and RI
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
Dependency Injection
Its is like parameterising but for classes,
During the construction, inject info
What to talk about in @post
- The result
- The variables that are modified
Which array can have null values
Can have null values:
- String array
Can’t have null values:
- Integer array
- Set integers
Dependency Inversion Principle
- 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
Key words
Testability
Resusibility
Understandability
Maintainability
Modifibility
Coupling
Cohesion
Describe the main steps (w.r.t. declaration and execution) for client code to use the SwingWorker class.
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().
Which of the following design patterns are used for Java’s SwingWorker?
- Facade
- Template
For ADTs, we distinguish between specification and implementation. Which of the following are part
of the specification of an ADT?
- Contracts for individual operations
- Zero or more public invariants
For ADTs, we distinguish between specification and implementation. Which of the following are part
of the Implemenation of an ADT?
- An abstraction function
- A representation invariant.
What are the advantages of throwing a Java exception instead of returning a special value to signal
a violated precondition?
- 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
In the context of abstract data types, what is encapsulation, and why is it useful?
- 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
What is functional decomposition?
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.
Explain one disadvantage of functional decomposition.
Disdvantages of Divide & Conquer
- Top-level divisions are hard to make: can have big consequences. Need experience and
need to experiment (try alternatives).
Advantages of automated test cases on manual ones
- 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.
Name at least four reasons why it is not a good idea to include unnecessary test
cases.
- 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.
What is the purpose of the SwingWorker class of Java?
It makes it easy to run some code in a background thread, and still interact with it in a
controlled way.
Describe the two main steps for client code to use the SwingWorker class?
- Some Swing component methods are labelled “thread safe” in the API specification: these
can be safely invoked from any thread. - All other Swing component methods must be invoked from the event dispatch thread.
Explain two design patterns which play a role in the SwingWorker, and what that
role is.
- SwingWorker acts as a Facade for the Java Thread facilities.
- 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()