33. created by
1. FizzBuzz mit TDD
Gegeben:
Zahlenreihe von 1 bis 100
Anforderung 1:
Alle Zahlen, die durch 3 teilbar sind,
sollen als `Fizz` dargestellt werden
34. created by
1. FizzBuzz mit TDD
Test:
const number = 3;
MapToFizzBuzzValue(number)
.Should()
.Be(`Fizz`)
35. created by
1. FizzBuzz mit TDD
Lösung:
public String MapToFizzBuzzValue(int number)
{
return `Fizz`;
}
36. created by
1. FizzBuzz mit TDD
Anforderung 2:
Alle Zahlen, die durch 5 teilbar sind,
sollen als `Buzz` dargestellt werden
37. created by
1. FizzBuzz mit TDD
Test:
const number = 5;
MapToFizzBuzzValue(number)
.Should()
.Be(`Buzz`)
38. created by
1. FizzBuzz mit TDD
Lösung:
public string MapToFizzBuzzValue(int number)
{
if(number % 5 == 0) return `Buzz`;
return `Fizz`;
}
39. created by
1. FizzBuzz mit TDD
Anforderung 3:
Alle Zahlen, die durch 3 und 5 teilbar
sind, sollen als `FizzBuzz`
dargestellt werden
40. created by
1. FizzBuzz mit TDD
Test:
const number = 15;
MapToFizzBuzzValue(number)
.Should()
.Be(`FizzBuzz`)
41. created by
1. FizzBuzz mit TDD
Lösung:
public String MapToFizzBuzzValue(int number)
{
if(number % 15 == 0) return `FizzBuzz`;
if(number % 5 == 0) return `Buzz`;
return `Fizz`;
}
43. created by
1. FizzBuzz mit TDD
Test:
const number = 23;
MapToFizzBuzzValue(number)
.Should()
.Be(`23`)
44. created by
1. FizzBuzz mit TDD
Lösung:
public String MapToFizzBuzzValue(int number)
{
if(number % 15 == 0) return `FizzBuzz`;
if(number % 3 == 0) return `Fizz`;
if(number % 5 == 0) return `Buzz`;
return number.ToString();
}
45. created by
2. Refactoring
Anforderung:
Es sollen Dateien aus einem FTP
Verzeichnis gelesen und verarbeitet
werden. In den Dateien sind
vermietbare Einheiten enthalten, die
je nach Status (Neu, Gelöscht,
Geändert) an das Vermietungsbüro
gemeldet werden sollen.
46. created by
2. Refactoring
Lösung: Im Prozess denken
var ftpFolder = new FtpFolder ();
GetFilesFrom (ftpFolder)
.ExtractUnits ()
.SortByState ()
.PublishTo (target);
47. created by
class MainClass
{
public static void Main (string[] args)
{
var ftpFolder = new FtpFolder ();
GetFilesFrom (ftpFolder)
.ExtractUnits ()
.SortByState ()
.PublishTo (target);
}
static FileList GetFilesFrom (FtpFolder ftpFolder)
{
return ftpFolder.FetchFiles();
}
}
class FtpFolder { … }
class FileList
{
private List<String> _files;
…
public Units ExtractUnits ()
{
return new Units ();
}
}
class Units
{
private List<Unit> _units;
…
public Units SortByState () { … }
public void PublishTo (ITarget target) { … }
}
• Fluent Interface
• Simple Types
• Single Responsibility
• Domain Specific
Terms
Lösung: Refactoring
49. created by
merci
thank you
danke
dekuji
tak dank je we
xièxie
kiitos
toda
köszönöm
go raibh maith agat
grazie
dziekuje
multumesc
spacibo
hvala
gracias
tack
mauruuru
tesekkur ederim
diakuiu
a dank