SlideShare ist ein Scribd-Unternehmen logo
1 von 51
Frank Kleine
Go OO
#IPC13
5 WICHTIGE DESIGN PATTERNS
Dienstag, 4. Juni 13
Lebt in
Karlsruhe
Nicht Stephan
Schmidt
Frank Kleine
Software
Architect
Dienstag, 4. Juni 13
Lebt in
Karlsruhe
Nicht Stephan
Schmidt
Frank Kleine
Software
Architect
Dienstag, 4. Juni 13
Frank Kleine
Go OO
#IPC13
5 WICHTIGE DESIGN PATTERNS
Dienstag, 4. Juni 13
Frank Kleine
Go OO
#IPC13
5 DESIGN PATTERNSvöllig subjektiv
ausgewählte
Dienstag, 4. Juni 13
Design
Patterns
1 2
Hilfreiche
Tipps
Dienstag, 4. Juni 13
5 Design Patterns
1
Dienstag, 4. Juni 13
Design Patterns?
Dienstag, 4. Juni 13
Definition: Wikipedia
Entwurfsmuster (englisch design patterns)
sind bewährte Lösungsschablonen für
wiederkehrende Entwurfsprobleme sowohl in
der Architektur als auch in der
Softwarearchitektur und -entwicklung. Sie
stellen damit eine wiederverwendbare Vorlage
zur Problemlösung dar, die in einem bestimmten
Zusammenhang einsetzbar ist.
Dienstag, 4. Juni 13
Definition: IKEA
Dienstag, 4. Juni 13
Composite
Dienstag, 4. Juni 13
Zweck
• Beliebige Zahl von Klassen gleicher Art soll für den Client wie eine
einzige Klasse erscheinen
• Verstecken von Hierarchien vor dem Client
• Logik des Zusammenschlusses soll für Client transparent bleiben
Dienstag, 4. Juni 13
Theorie
Dienstag, 4. Juni 13
Beispiel: Conditions
$condition = new AndCondition();
$condition->addCondition(new FooCondition())
$or = new OrCondition();
$or->addCondition(new BarCondition());
$or->addCondition(new BazCondition());
$condition->addCondition($or);
if ($condition->isValid(‘foo.txt‘)) {
echo ‘Is valid!‘;
}
Dienstag, 4. Juni 13
Beispiel: Doctrine
$logger = new LoggerChain();
$logger->addLogger(new EchoSQLLogger());
$logger->addLogger(new DebugStack());
$conn->getConfiguration()->setSQLLogger($logger):
Dienstag, 4. Juni 13
Decorator
Dienstag, 4. Juni 13
Zweck
• Hinzufügen neuer Funktionalität zur Laufzeit
• Vorhandene Funktionalität ändern
• Verschiedene Funktionalitäten kombinieren
• Nutzung von Komposition statt Vererbung
Dienstag, 4. Juni 13
Theorie
Dienstag, 4. Juni 13
Beispiel: Symfony2
$kernel = new HttpKernel($dispatcher, $resolver);
$kernel = new HttpCache($kernel,
new Store(__DIR__.'/cache'));
$kernel->handle($request)->send();
Dienstag, 4. Juni 13
Beispiel: Symfony2
$kernel = new HttpKernel($dispatcher, $resolver);
$kernel = new HttpCache($kernel,
new Store(__DIR__.'/cache'));
$kernel->handle($request)->send();
public function handle($request) {
if ($this->hasCachedResponse($request) {
return $this->getCachedResponse($request);
}
$response = $this->originalKernel->handle($request);
$this->store($response);
return $response;
}
Dienstag, 4. Juni 13
Beispiel: stackphp
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpKernelHttpCacheStore;
$app = new SilexApplication();
$app->get('/', function () {
return 'Hello World!';
});
$stack = (new StackBuilder())
->push('StackSession')
->push('SymfonyComponentHttpKernelHttpCache
HttpCache', new Store(__DIR__.'/cache'));
$app = $stack->resolve($app);
$request = Request::createFromGlobals();
$response = $app->handle($request)->send();
Dienstag, 4. Juni 13
Template Method
Dienstag, 4. Juni 13
Zweck
• Sicherstellen der Reihenfolge von Schritten, mit der Möglichkeit einzelne
Schritte unterschiedlich zu implementieren
• Einzelschritte können mit Standardmethode bereit gestellt und damit
optional überschrieben werden
Dienstag, 4. Juni 13
Theorie
Dienstag, 4. Juni 13
Beispiel
abstract class Recipe {
public function prepare() {
$this->collectIngredients();
$this->prepareIngredients();
return $this->cook();
}
protected abstract function collectIngredients();
protected abstract function prepareIngredients();
protected abstract function cook();
}
class CheeseburgerRecipe extends Recipe {
protected function collectIngredients() { ... }
protected function prepareIngredients() { ... }
protected function cook() { ... }
}
Dienstag, 4. Juni 13
Command
Dienstag, 4. Juni 13
Zweck
• Ausführen von Aktionen ohne dass Client konkrete Aktion kennt
• Beliebige Kombinationen verschiedener Aktionen
• Optional: Bereitstellung von Undo-Funktionalität (jedoch kein Bestandteil
des Patterns selbst)
Dienstag, 4. Juni 13
Theorie
Dienstag, 4. Juni 13
Beispiel: Cart Mapping
interface MappingCommand {
function execute(Context $context, Cart $cart);
function undo(Context $context, Cart $cart);
}
class Mapping {
...
function applyMapping(Context $context , Cart $cart) {
foreach ($this->mapCommands as $mapCommand) {
$mapCommand->execute($context, $cart);
}
}
}
Dienstag, 4. Juni 13
Moment...
• Command dient zum Herumreichen von Code.
• Das geht doch auch mit Closures...
Dienstag, 4. Juni 13
Beispiel: callable
class Batch {
private $commands = array();
public function addCommand(callable $command) {
$this->commands = $command;
}
public function execute(Directory $dir) {
foreach ($this->commands as $command) {
$command($dir);
}
}
}
$batch = new Batch();
$batch->addCommand(function (Directory $dir) { ... });
$batch->addCommand([‘Example‘, ‘clear‘]);
$batch->execute();
Dienstag, 4. Juni 13
Visitor
Dienstag, 4. Juni 13
Zweck
• Hinzufügen neuer Operationen zu einer Objektstruktur
• Neue Operationen werden im Visitor gekapselt
• Achtung: gegebenenfalls Aufbruch der Kapselung in Objektstruktur
erforderlich
Dienstag, 4. Juni 13
Theorie
Dienstag, 4. Juni 13
Beispiel: vfsStream
vfsStream::setup(‘root‘, null, $complexStructure);
vfsStream::inspect(new vfsStreamPrintVisitor());
interface vfsStreamVisitor {
function visit(vfsStreamContent $content);
function visitFile(vfsStreamFile $file);
function visitDirectory(vfsStreamDirectory $dir);
}
Dienstag, 4. Juni 13
Achtung
• Visitor in vfsStream kennt Datenstruktur - leichte Abwandlung des
Originalpatterns
• Original: Visitor kennt Datenobjekte, aber nicht Datenstruktur
• Datenstruktur reicht Visitor intern durch
Dienstag, 4. Juni 13
Beispiel: Original
class RentalAction {
...
public function accept(Visitor $visitor) {
$visitor->visitRentalAction($this);
$this->vehicle->accept($visitor);
$this->customer->accept($visitor);
}
}
interface Visitor {
function visitRentalAction(RentalAction $rent);
function visitVehicle(Vehicle $vehicle);
function visitCustomer(Customer $customer);
}
$visitor = new DebugVisitor();
$rentalAction->accept($visitor);
Dienstag, 4. Juni 13
5 Hilfreiche Tipps
2
Dienstag, 4. Juni 13
Klasse statt Masse
Dienstag, 4. Juni 13
OO in der Königsklasse
• Viele kleine Klassen, die sich miteinander kombinieren lassen
• Große, umfangreiche Klassen führen zu geringer Flexibilität und sind eine
Garantie für die Wartungshölle
• Lieber Massen von Klassen statt viel Masse in einer Klasse
Dienstag, 4. Juni 13
Design Patterns sind ein Gewürz
Dienstag, 4. Juni 13
Hinweise zum Einsatz
• Design Patterns sollen den Code besser strukturieren und verständlicher
machen
• Zu viel davon und der Code wird ungenießbar
• Das Pattern von heute ist das Anti-Pattern von morgen
Dienstag, 4. Juni 13
Manchmal reicht eine Funktion
Dienstag, 4. Juni 13
Funktionen
• Es muss nicht immer eine Methode in einer Klasse sein
• Vorsicht vor Klassen wie Utility, Helper o.ä.
• Autoload?
Dienstag, 4. Juni 13
Composer hilft weiter
"autoload": {
"psr-0": {
"examplefoo": "src"
},
"files": ["src/functions.php",
"src/other/functions.php"
]
}
Dienstag, 4. Juni 13
Namen sind nicht Schall und Rauch
Dienstag, 4. Juni 13
Namen
• Code kommuniziert.
• Der erste Name ist immer falsch.
• Wenn sich kein passender Name findet: Fachliches Verständnis falsch?
Code überdenken und umbauen.
Dienstag, 4. Juni 13
Die erste Lösung ist falsch.
Dienstag, 4. Juni 13
Mindestens nicht richtig.
• Nie bei der ersten Lösung bleiben - sie mag zwar nicht falsch sein, ist
aber wahrscheinlich auch nicht korrekt.
• Selbst wenn sie richtig ist: es geht immer noch einfacher.
• Mit anderen darüber reden hilft.
Dienstag, 4. Juni 13
www. phpdesignpatterns .de
Dienstag, 4. Juni 13
@BOVIGO
HTTPS://JOIND.IN/8776
VIELEN DANK
Dienstag, 4. Juni 13

Weitere ähnliche Inhalte

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Go OO! 5 wichtige Design Patterns

  • 1. Frank Kleine Go OO #IPC13 5 WICHTIGE DESIGN PATTERNS Dienstag, 4. Juni 13
  • 2. Lebt in Karlsruhe Nicht Stephan Schmidt Frank Kleine Software Architect Dienstag, 4. Juni 13
  • 3. Lebt in Karlsruhe Nicht Stephan Schmidt Frank Kleine Software Architect Dienstag, 4. Juni 13
  • 4. Frank Kleine Go OO #IPC13 5 WICHTIGE DESIGN PATTERNS Dienstag, 4. Juni 13
  • 5. Frank Kleine Go OO #IPC13 5 DESIGN PATTERNSvöllig subjektiv ausgewählte Dienstag, 4. Juni 13
  • 9. Definition: Wikipedia Entwurfsmuster (englisch design patterns) sind bewährte Lösungsschablonen für wiederkehrende Entwurfsprobleme sowohl in der Architektur als auch in der Softwarearchitektur und -entwicklung. Sie stellen damit eine wiederverwendbare Vorlage zur Problemlösung dar, die in einem bestimmten Zusammenhang einsetzbar ist. Dienstag, 4. Juni 13
  • 12. Zweck • Beliebige Zahl von Klassen gleicher Art soll für den Client wie eine einzige Klasse erscheinen • Verstecken von Hierarchien vor dem Client • Logik des Zusammenschlusses soll für Client transparent bleiben Dienstag, 4. Juni 13
  • 14. Beispiel: Conditions $condition = new AndCondition(); $condition->addCondition(new FooCondition()) $or = new OrCondition(); $or->addCondition(new BarCondition()); $or->addCondition(new BazCondition()); $condition->addCondition($or); if ($condition->isValid(‘foo.txt‘)) { echo ‘Is valid!‘; } Dienstag, 4. Juni 13
  • 15. Beispiel: Doctrine $logger = new LoggerChain(); $logger->addLogger(new EchoSQLLogger()); $logger->addLogger(new DebugStack()); $conn->getConfiguration()->setSQLLogger($logger): Dienstag, 4. Juni 13
  • 17. Zweck • Hinzufügen neuer Funktionalität zur Laufzeit • Vorhandene Funktionalität ändern • Verschiedene Funktionalitäten kombinieren • Nutzung von Komposition statt Vererbung Dienstag, 4. Juni 13
  • 19. Beispiel: Symfony2 $kernel = new HttpKernel($dispatcher, $resolver); $kernel = new HttpCache($kernel, new Store(__DIR__.'/cache')); $kernel->handle($request)->send(); Dienstag, 4. Juni 13
  • 20. Beispiel: Symfony2 $kernel = new HttpKernel($dispatcher, $resolver); $kernel = new HttpCache($kernel, new Store(__DIR__.'/cache')); $kernel->handle($request)->send(); public function handle($request) { if ($this->hasCachedResponse($request) { return $this->getCachedResponse($request); } $response = $this->originalKernel->handle($request); $this->store($response); return $response; } Dienstag, 4. Juni 13
  • 21. Beispiel: stackphp use SymfonyComponentHttpFoundationRequest; use SymfonyComponentHttpKernelHttpCacheStore; $app = new SilexApplication(); $app->get('/', function () { return 'Hello World!'; }); $stack = (new StackBuilder()) ->push('StackSession') ->push('SymfonyComponentHttpKernelHttpCache HttpCache', new Store(__DIR__.'/cache')); $app = $stack->resolve($app); $request = Request::createFromGlobals(); $response = $app->handle($request)->send(); Dienstag, 4. Juni 13
  • 23. Zweck • Sicherstellen der Reihenfolge von Schritten, mit der Möglichkeit einzelne Schritte unterschiedlich zu implementieren • Einzelschritte können mit Standardmethode bereit gestellt und damit optional überschrieben werden Dienstag, 4. Juni 13
  • 25. Beispiel abstract class Recipe { public function prepare() { $this->collectIngredients(); $this->prepareIngredients(); return $this->cook(); } protected abstract function collectIngredients(); protected abstract function prepareIngredients(); protected abstract function cook(); } class CheeseburgerRecipe extends Recipe { protected function collectIngredients() { ... } protected function prepareIngredients() { ... } protected function cook() { ... } } Dienstag, 4. Juni 13
  • 27. Zweck • Ausführen von Aktionen ohne dass Client konkrete Aktion kennt • Beliebige Kombinationen verschiedener Aktionen • Optional: Bereitstellung von Undo-Funktionalität (jedoch kein Bestandteil des Patterns selbst) Dienstag, 4. Juni 13
  • 29. Beispiel: Cart Mapping interface MappingCommand { function execute(Context $context, Cart $cart); function undo(Context $context, Cart $cart); } class Mapping { ... function applyMapping(Context $context , Cart $cart) { foreach ($this->mapCommands as $mapCommand) { $mapCommand->execute($context, $cart); } } } Dienstag, 4. Juni 13
  • 30. Moment... • Command dient zum Herumreichen von Code. • Das geht doch auch mit Closures... Dienstag, 4. Juni 13
  • 31. Beispiel: callable class Batch { private $commands = array(); public function addCommand(callable $command) { $this->commands = $command; } public function execute(Directory $dir) { foreach ($this->commands as $command) { $command($dir); } } } $batch = new Batch(); $batch->addCommand(function (Directory $dir) { ... }); $batch->addCommand([‘Example‘, ‘clear‘]); $batch->execute(); Dienstag, 4. Juni 13
  • 33. Zweck • Hinzufügen neuer Operationen zu einer Objektstruktur • Neue Operationen werden im Visitor gekapselt • Achtung: gegebenenfalls Aufbruch der Kapselung in Objektstruktur erforderlich Dienstag, 4. Juni 13
  • 35. Beispiel: vfsStream vfsStream::setup(‘root‘, null, $complexStructure); vfsStream::inspect(new vfsStreamPrintVisitor()); interface vfsStreamVisitor { function visit(vfsStreamContent $content); function visitFile(vfsStreamFile $file); function visitDirectory(vfsStreamDirectory $dir); } Dienstag, 4. Juni 13
  • 36. Achtung • Visitor in vfsStream kennt Datenstruktur - leichte Abwandlung des Originalpatterns • Original: Visitor kennt Datenobjekte, aber nicht Datenstruktur • Datenstruktur reicht Visitor intern durch Dienstag, 4. Juni 13
  • 37. Beispiel: Original class RentalAction { ... public function accept(Visitor $visitor) { $visitor->visitRentalAction($this); $this->vehicle->accept($visitor); $this->customer->accept($visitor); } } interface Visitor { function visitRentalAction(RentalAction $rent); function visitVehicle(Vehicle $vehicle); function visitCustomer(Customer $customer); } $visitor = new DebugVisitor(); $rentalAction->accept($visitor); Dienstag, 4. Juni 13
  • 40. OO in der Königsklasse • Viele kleine Klassen, die sich miteinander kombinieren lassen • Große, umfangreiche Klassen führen zu geringer Flexibilität und sind eine Garantie für die Wartungshölle • Lieber Massen von Klassen statt viel Masse in einer Klasse Dienstag, 4. Juni 13
  • 41. Design Patterns sind ein Gewürz Dienstag, 4. Juni 13
  • 42. Hinweise zum Einsatz • Design Patterns sollen den Code besser strukturieren und verständlicher machen • Zu viel davon und der Code wird ungenießbar • Das Pattern von heute ist das Anti-Pattern von morgen Dienstag, 4. Juni 13
  • 43. Manchmal reicht eine Funktion Dienstag, 4. Juni 13
  • 44. Funktionen • Es muss nicht immer eine Methode in einer Klasse sein • Vorsicht vor Klassen wie Utility, Helper o.ä. • Autoload? Dienstag, 4. Juni 13
  • 45. Composer hilft weiter "autoload": { "psr-0": { "examplefoo": "src" }, "files": ["src/functions.php", "src/other/functions.php" ] } Dienstag, 4. Juni 13
  • 46. Namen sind nicht Schall und Rauch Dienstag, 4. Juni 13
  • 47. Namen • Code kommuniziert. • Der erste Name ist immer falsch. • Wenn sich kein passender Name findet: Fachliches Verständnis falsch? Code überdenken und umbauen. Dienstag, 4. Juni 13
  • 48. Die erste Lösung ist falsch. Dienstag, 4. Juni 13
  • 49. Mindestens nicht richtig. • Nie bei der ersten Lösung bleiben - sie mag zwar nicht falsch sein, ist aber wahrscheinlich auch nicht korrekt. • Selbst wenn sie richtig ist: es geht immer noch einfacher. • Mit anderen darüber reden hilft. Dienstag, 4. Juni 13