Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Nanos gigantium
humeris insidentes
DESIGN PATTERN INSIDE SYMFONY2
GIANTS
liurrrgio
GIULIO DE DONATO

GIORGIO CEFARO

@liuggio

@giorrrgio
DESIGN PATTERN?
DESIGN PATTERN

A solution of a
problem in a context
James O. Coplien (1994)
DESIGN PATTERN

“ For me a pattern is
primarily a way to chunk up
advice about a topic “
#1
FRONT CONTROLLER
INTENT:

A controller that handles
all requests for a Web site
FRONT CONTROLLER
web/app.php
FRONT CONTROLLER ... and ?
web/app.php
INTENT:

DECORATOR

Attach additional responsibilities
to an object dynamically.
Decorators provide a flexible
alternative...
DECORATOR
SymfonyComponentHttpKernelHttpCacheHttpCache
U DUNNO
HttpKernelInterface?
SymfonyComponentHttpKernelHttpKernelInterface
KERNEL AND SERVICE CONTAINER
SymfonyComponentHttpKernelKernel
INVERSION OF CONTROL
INTENT:

Inversion of control is a style
of software construction where
reusable code controls the ex...
INVERSION OF CONTROL

1988
“ Inversion of control is a common
characteristic of frameworks,
so saying that these lightweight containers
are special b...
INVERSION OF CONTROL
HOLLYWOOD PRINCIPLE:

“ DON’T CALL US
WE’LL CALL YOU ”
INVERSION OF CONTROL
PICO CONTAINER DEFINITION:

"Dependency Injection is where
components are given their
dependencies through their
construct...
Dependency injection allows the
removal of hard-coded dependencies
and makes it possible to change
them, whether at run-ti...
INJECTING A TRANSPORT INSIDE A MAILER
- FIGHT OF THE DAY -

SERVICE CONTAINER
vs
DEPENDENCY INJECTION
INVERSION OF CONTROL
INTENT:

DECOUPLE DECOUPL
DECOUPLE
DECOUPLE
DECOUPLE
DECOUPLE

DECOUPLE
DECOUPLE
DECOUPLE

DECOUPLE
DEPENDENCY INJECTION AND FRAMEWORKS
DI

??

Grafico con spaghetti, infermiera che fa la
puntura, lista della spesa per l'a...
FACTORY METHOD
INTENT:

Define an interface for creating an object,
but let subclasses decide which class
to instantiate.
...
FACTORY METHOD - DO IT WITH THE DIC
ABSTRACT FACTORY
INTENT:

Provide an interface for creating
families of related or dependent
objects without
specifying th...
ABSTRACT FACTORY - SecurityFactoryInterface
SymfonyBundleSecurityBundleDependencyInjectionSecurityFactorySecurityFactoryIn...
INTENT:

BUILDER

Separate the construction of a
complex object from its
representation so that the same
construction proc...
FORM BUILDER
SymfonyComponentFormFormBuilderInterface
FORM BUILDER
PROXY
INTENT:

Provide a surrogate or
placeholder for another
object to control access to it.
DOCTRINE PROXY
app/cache/doctrine/odm/Proxies/ ...
MEDIATOR
INTENT:

Define an object that encapsulates how a set
of objects interact. Mediator promotes loose
coupling by ke...
ner

file

Kernel :: REQUEST

rLi

ste

gm
ent
Fra

ste

Li
on

ssi

Se

Pro

List
ene

r

MEDIATOR

er

ten
rLis

te

Rou...
STRATEGY aka POLICY
INTENT:

Defines a family of algorithms, encapsulate
each one, and make them interchangeable.
Strategy...
FragmentRendererInterface
SymfonyComponentHttpKernelFragmentFragmentRendererInterface
Fragment Renderers
SymfonyComponentHttpKernelFragment...
DATA MAPPER
INTENT:

A layer of Mappers that moves data between
objects and a database while keeping them
independent of e...
VISITOR
INTENT:

Represent an operation to be performed on
the elements of an object structure.
Visitor lets you define a ...
VALIDATION VISITOR
SymfonyComponentValidator..
MVC
er

n
Co

ll
tro

w
Vie

el

d
Mo
AbstractionInversion,
AccidentalComplexity,
AccidentalInclusion,
AddingEpicycles,
AlcoholFueledDevelopment,
AmbiguousViewp...
DESIGN
FOR THE SAKE OF DESIGN
“I only ship the perfection"
ANTI PATTERNS
OVER ENGINEERING
OVERUSE OF PATTERNS
ANTI PATTERNS
THE BLOB
BIG BALL OF MUD
ANTI PATTERNS
GLOBALIZING
STANDING ON THE SHOULDER OF THE MIDGETS
ANTI PATTERNS
REINVENTING THE WHEEL
NIH SYNDROME
ANTI PATTERNS
E
D
O
C
SPAGHETTI WITHIMEATBALL
L
IO CODE
LASAGNA
V
A
R
SPAGHETTI CODE
code spends
more time being read
and maintained than
being created
DECOUPLE
DECOUPLE
DECOUPLE.
GOOD QUESTIONS
ARE BETTER THAN
GOOD ANSWERS
REFERENCES
1.

https://gist.github.com/giorrrgio/d4395afe470a1ad223e0

2.

http://12factor.net

3.

http://obvioushints.bl...
Design pattern in Symfony2 - Nanos gigantium humeris insidentes
Upcoming SlideShare
Loading in …5
×

Design pattern in Symfony2 - Nanos gigantium humeris insidentes

30,532 views

Published on

Giorgio Cefaro and Giulio De Donato - Symfony day in Rome 2014.

Published in: Technology

Design pattern in Symfony2 - Nanos gigantium humeris insidentes

  1. 1. Nanos gigantium humeris insidentes DESIGN PATTERN INSIDE SYMFONY2
  2. 2. GIANTS
  3. 3. liurrrgio GIULIO DE DONATO GIORGIO CEFARO @liuggio @giorrrgio
  4. 4. DESIGN PATTERN?
  5. 5. DESIGN PATTERN A solution of a problem in a context James O. Coplien (1994)
  6. 6. DESIGN PATTERN “ For me a pattern is primarily a way to chunk up advice about a topic “
  7. 7. #1
  8. 8. FRONT CONTROLLER INTENT: A controller that handles all requests for a Web site
  9. 9. FRONT CONTROLLER web/app.php
  10. 10. FRONT CONTROLLER ... and ? web/app.php
  11. 11. INTENT: DECORATOR Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
  12. 12. DECORATOR SymfonyComponentHttpKernelHttpCacheHttpCache
  13. 13. U DUNNO HttpKernelInterface? SymfonyComponentHttpKernelHttpKernelInterface
  14. 14. KERNEL AND SERVICE CONTAINER SymfonyComponentHttpKernelKernel
  15. 15. INVERSION OF CONTROL INTENT: Inversion of control is a style of software construction where reusable code controls the execution of problem-specific code
  16. 16. INVERSION OF CONTROL 1988
  17. 17. “ Inversion of control is a common characteristic of frameworks, so saying that these lightweight containers are special because they use inversion of control is like saying my car is special because it has wheels.”
  18. 18. INVERSION OF CONTROL HOLLYWOOD PRINCIPLE: “ DON’T CALL US WE’LL CALL YOU ”
  19. 19. INVERSION OF CONTROL
  20. 20. PICO CONTAINER DEFINITION: "Dependency Injection is where components are given their dependencies through their constructors, methods, or directly into fields."
  21. 21. Dependency injection allows the removal of hard-coded dependencies and makes it possible to change them, whether at run-time or compiletime.
  22. 22. INJECTING A TRANSPORT INSIDE A MAILER
  23. 23. - FIGHT OF THE DAY - SERVICE CONTAINER vs DEPENDENCY INJECTION
  24. 24. INVERSION OF CONTROL INTENT: DECOUPLE DECOUPL DECOUPLE DECOUPLE DECOUPLE DECOUPLE DECOUPLE DECOUPLE DECOUPLE DECOUPLE
  25. 25. DEPENDENCY INJECTION AND FRAMEWORKS DI ?? Grafico con spaghetti, infermiera che fa la puntura, lista della spesa per l'antipattern service locator, qualcosa di galattico per l'enhanced injection (tipo pulp fiction) http://www.loosecouplings.com/2011/01/dependency-injection-using-di-container.html DIC
  26. 26. FACTORY METHOD INTENT: Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
  27. 27. FACTORY METHOD - DO IT WITH THE DIC
  28. 28. ABSTRACT FACTORY INTENT: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
  29. 29. ABSTRACT FACTORY - SecurityFactoryInterface SymfonyBundleSecurityBundleDependencyInjectionSecurityFactorySecurityFactoryInterface
  30. 30. INTENT: BUILDER Separate the construction of a complex object from its representation so that the same construction process can create different representations.
  31. 31. FORM BUILDER SymfonyComponentFormFormBuilderInterface
  32. 32. FORM BUILDER
  33. 33. PROXY INTENT: Provide a surrogate or placeholder for another object to control access to it.
  34. 34. DOCTRINE PROXY app/cache/doctrine/odm/Proxies/ ...
  35. 35. MEDIATOR INTENT: Define an object that encapsulates how a set of objects interact. Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.
  36. 36. ner file Kernel :: REQUEST rLi ste gm ent Fra ste Li on ssi Se Pro List ene r MEDIATOR er ten rLis te Rou ner EVENT DISPATCHER Loca leLis tene r all ew Fir
  37. 37. STRATEGY aka POLICY INTENT: Defines a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
  38. 38. FragmentRendererInterface SymfonyComponentHttpKernelFragmentFragmentRendererInterface
  39. 39. Fragment Renderers SymfonyComponentHttpKernelFragment...
  40. 40. DATA MAPPER INTENT: A layer of Mappers that moves data between objects and a database while keeping them independent of each other and the mapper itself.
  41. 41. VISITOR INTENT: Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.
  42. 42. VALIDATION VISITOR SymfonyComponentValidator..
  43. 43. MVC er n Co ll tro w Vie el d Mo
  44. 44. AbstractionInversion, AccidentalComplexity, AccidentalInclusion, AddingEpicycles, AlcoholFueledDevelopment, AmbiguousViewpoint, AnalogyBreakdownAntiPattern, AnalysisParalysis, AnAthena, AppointedTeam, ArchitectsDontCode, ArchitectsPlayGolf, ArchitectureAsRequirements, ArchitectureByImplication, AsynchronousUnitTesting, AutogeneratedStovepipeAntiPattern, BandAid, BearTrap?, BigBallOfMud, BlameStorming, BlowhardJamboree, BoatAnchor, CargoCult, CarParkSyndrome, CascadingDialogBoxesAntiPattern, ContinuousObsolescence, ConfusionOfObjectives, ControlFreak, CopyAndPasteProgramming, CornCob, CoverYourAssets, CreepingFeaturitis, CrciCards, CryptoCracy, DeadEnd, DeathByPlanning, DecisionByArithmetic, DesignByCommittee, DesignForTheSakeOfDesign., DiscordantRewardMechanisms, DoerAndKnower, DryWaterhole, EgalitarianCompensation, EmailIsDangerous, EmperorsNewClothes, EmpireBuilding, ExceptionFunnel, FalseEconomy, FalseSurrogateEndpoint, FearOfSuccess, FireDrill, FloatingPointCurrency, FloatingPointFractions, FoolTrap, FunctionalDecomposition, FungibleTeams, FungibleProjectManager, GeographicallyDistributedDevelopment, GiveMeEstimatesNow, GlassWall, GodClass, GoldenHammer, GroundHogDayProject, HalfDoneIsEnough, HeirApparent, HeroCulture, HiddenRequirements, IdiotProofProcess., IfItIsWorkingDontChange, IfOk, InappropriateTechnicalObjective, InputKludge, ItsAnOperatorProblem, JobKeeper, JumbleAntipattern, JunkyardCoding, KillTwoBirdsWithOneStone, KitchenSinkDesign, LavaFlow, LeadingRequest, MagicContainer, ManagerControlsProcess, MushroomManagement, Nationalism, NetNegativeProducingProgrammer, NotInventedHere, NotTheAppropriateProtocol, NullFlag, OverGeneralizationOfBusinessLogic, OverUseOfPatterns, PathOfLeastResistance, ParsingHtmlWithRegex, PassingNullsToConstructors, PlugCompatibleInterchangeableEngineers, PoliticsOrientedArchitecture, PolterGeists, ReinventingTheWheel, ReinventTheWheel, RollYourOwnDatabase, RequirementsTossedOverTheWall, RubeGoldbergMachine, ScapeGoat, SeagullManagement, SecretSociety, SellingaProductYouCantRealize, ShootTheMessenger, SingleFunctionExitPoint, SmokeAndMirrors, SoftwareMerger, SpaghettiCode, SpecifyNothing, StandingOnTheShouldersOfMidgets, StovepipeAntiPattern, StringWithoutLength, SumoMarriage, SweepItUnderTheRugAntiPattern, SwissArmyKnife, ThatsNotReallyAnIssue, TheBlob, TheCustomersAreIdiots, TheGrandOldDukeOfYork, TheProcessIsTheDeliverable, TheyUnderstoodMe, ThrownOverTheWall, TowerOfVoodoo, TrainTheTrainer, UntestedButFinished, VendorLockIn, ViewgraphEngineering, VietnamWarAntiPattern, VoodooChickenCoding, WalkingThroughaMineField, WarmBodies, WeAreIdiots, WolfTicket, YetAnotherMeetingWillSolveIt, YetAnotherThreadWillSolveIt, ANTI-PATTERN
  45. 45. DESIGN FOR THE SAKE OF DESIGN “I only ship the perfection" ANTI PATTERNS
  46. 46. OVER ENGINEERING OVERUSE OF PATTERNS ANTI PATTERNS
  47. 47. THE BLOB BIG BALL OF MUD ANTI PATTERNS
  48. 48. GLOBALIZING STANDING ON THE SHOULDER OF THE MIDGETS ANTI PATTERNS
  49. 49. REINVENTING THE WHEEL NIH SYNDROME ANTI PATTERNS
  50. 50. E D O C SPAGHETTI WITHIMEATBALL L IO CODE LASAGNA V A R SPAGHETTI CODE
  51. 51. code spends more time being read and maintained than being created
  52. 52. DECOUPLE
  53. 53. DECOUPLE
  54. 54. DECOUPLE.
  55. 55. GOOD QUESTIONS ARE BETTER THAN GOOD ANSWERS
  56. 56. REFERENCES 1. https://gist.github.com/giorrrgio/d4395afe470a1ad223e0 2. http://12factor.net 3. http://obvioushints.blogspot.it/2008/12/symfony-design-patterns.html 4. http://c2.com/cgi/wiki?AntiPatternsCatalog 5. http://martinfowler.com/bliki/InversionOfControl.html 6. http://martinfowler.com/articles/injection.html

×