100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Programming Methods (2IPC0) Summary Q2 2020 $4.48   Add to cart

Summary

Programming Methods (2IPC0) Summary Q2 2020

1 review
 104 views  5 purchases
  • Course
  • Institution

EN: Programming Methods (2IPC0) is a course taught at Eindhoven University of Technology. It is a mandatory course for Bachelor Computer Science and Engineering students. The course is given in the second quartile of the second year. Programming Methods discusses design patterns, test-driven develo...

[Show more]
Last document update: 3 year ago

Preview 3 out of 20  pages

  • January 28, 2021
  • January 28, 2021
  • 20
  • 2020/2021
  • Summary

1  review

review-writer-avatar

By: marcelroohappyroozen • 8 months ago

avatar-seller
Programming Methods (2IPC0) Summary Q2 2020

Table of Contents
Handouts .............................................................................................................................. 2
Notation ............................................................................................................................. 2
Specification ...................................................................................................................... 2
Callback ............................................................................................................................ 2
Test-Driven development................................................................................................... 3
UML Diagram .................................................................................................................... 4
Design Patterns .................................................................................................................... 6
Singleton (Creational) ........................................................................................................ 6
Iterator (Behavioral) ........................................................................................................... 7
Adapter (Structural) ........................................................................................................... 8
Decorator (Structural) ........................................................................................................ 9
State (Behavioral) ............................................................................................................ 10
Strategy (Behavioral) ....................................................................................................... 11
Factory method (Creational) ............................................................................................ 12
Observer (Behavioral) ..................................................................................................... 13
Façade (Structural) .......................................................................................................... 13
Template Method (Behavioral) ........................................................................................ 14
Composite (Structural) ..................................................................................................... 15
Command (Behavioral) .................................................................................................... 15
Slides .................................................................................................................................. 16
Kick-off lecture................................................................................................................. 16
Lecture 1 ......................................................................................................................... 16
Lecture 2 ......................................................................................................................... 17
Lecture 3 ......................................................................................................................... 18
Lecture 4 ......................................................................................................................... 18
Lecture 5 ......................................................................................................................... 19
Lecture 6 ......................................................................................................................... 19
Lecture 7 ......................................................................................................................... 20




1
Programming Methods (2IPC0) summary Q2 2020 by Isabel Rutten

,Handouts
Notation
Quantified expression take the form (quantifier quantified-var-decls; predicate; spec-
expression) where quantifier is the operator; quantified-var-decls introduces the dummy or
dummies which are officially required to include a type but when clear from the context we
omit this; predicate expresses the range for the dummy where leaving out is the same as
writing true; spec-expression is the quantified term of appropriate type.




Precondition and postcondition are predicates. Modifies clauses provides list of all variables
that the method can modify. Return clause is an expression of method’s return type.
“Returns: F” and “Postcondition: \result == F” express the same.
Special JML symbols: \result in postconditions for return value of method that follows;
\old(expression) in postconditions/returns clauses for referring to value of expression at time
of entry into a method
e.g.: for all 𝑎, if 𝑎|6, then also a|2 & a|3: (\forall int a; a % 6 == 0; a % 2 == 0 && a % 3 == 0)
Specification
Formal definitions should first aim at understandability. The same thing can be written in
multiple ways but you want the most understandable one.
Split longer definitions by making separate predicates.
It is useful to define auxiliary predicates (Divide and Conquer).
It is helpful to parameterize the definition as it makes it easier to express properties. Do not
make everything a parameter as that can clutter the notation.
After giving formal definition, useful to rewrite it into alternative forms, depending on its role
in the reasoning (e.g. established/exploited). May improve understanding or problem solving.
Balance formality depending on purpose: in user interface, it’s hard to be formal. So weight
the effort and benefits for the level of formality.
Changing a single symbol can make a huge difference in meaning.
So, formal definitions must be written as clearly as possible + are advisably accompanied by
informal description to state and prove some elementary properties of the defined concept.
Callback
Want to incorporate code of functionality B into functionality A:
- merging code. Con: harder to test/reuse, may break functionality, hard coupling
- divide and conquer - function as parameter (callback)
Put function as a method inside a class and pass object of the class as parameter for even
more flexibility, we typically define an interface that contains signature of callback method.
=> Dependency Inversion Principle (DIP): depend on abstractions (interface), not on
concrete implementations.
Strategy pattern: each way of processing (B) is referred to as a strategy
In the end all about decoupling (reducing dependencies so easier to test/change code) and
avoiding code duplication.

2
Programming Methods (2IPC0) summary Q2 2020 by Isabel Rutten

, Test-Driven development
TDD is a technique that concerns the development process rather than the developed
product. The development is driven by tests. Steps:
1. Gather and analyze requirements.
2. Decide which requirements to develop next and what module it concerns.
3. Specify the module informally in source code, using natural language.
4. Specify the module formally, by providing its interface and contract.
5. Design and implement a test case and document its motivation in source code.
6. Design and implement module features, intended to make the test case pass.
7. Test the new module implementation and fix defects found (to step 6).
8. Where relevant improve structure (refactor) preserving correctness (regression testing).
9. Repeat from step 5 until the entire module has been implemented and tested.
10. If a defect is reported after delivery: first add test case, then fix defect.
Motivation for TDD: the longer a defect remains undetected, the higher the cost of fixing it.
Written down test cases are better verifiable and reproducible, serve as documentation and
are used to verify the requirements if test case state motivation, input, output, pass criteria.
Automated test cases are more convenient, faster and more reliable. It makes it easier to
find bugs, requirements are operationalized, interfaces and contracts are stabilized, it
encourages analysis before implementation, there’s no interruption between test and fixing.
TDD for a single function: single function:
/**
* informal specification, elaborated to remove ambiguities and imprecisions
* formal specifications/contract with @param, @return, @pre, @post
*/
public state Type nameFunction(TypeInput, inputName) {
implemented function using inputName
}
Test for a single function:
import static org.junit.Assert.*;
import org.junit.Test;
/* invokes nameFunction and checks result
* formal specifications/contract with @param, @pre
*/
private void checkNameFunction(TypeInput inputName, expResult) {
System.out.println(“…”.assertEquals(“result”, expres; result); }
/* Test of … *\
@Test
public void testCountDigits9() {
checkNameFunction(9L, 1);
}
One can add more such test cases to improve code based on these test cases.
Here are the steps for developing a class that will serve as an Abstract Data Type (ADT):
1. Gather and analyze the requirements to realize, e.g. use cases or user stories.
2. Decide which requirements to develop next, and what module it concerns.
3. Specify the class informally:
a) Provide a one-sentence summary of the class in a Javadoc comment;
b) Choose an appropriate class name;
c) When relevant, choose generic type parameters and their constraints;
d) Elaborate the informal description to obtain a more complete description of the class as a
whole, from the perspective of a client of the class
3
Programming Methods (2IPC0) summary Q2 2020 by Isabel Rutten

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller IsabelRutten. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $4.48. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

79978 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$4.48  5x  sold
  • (1)
  Add to cart